mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-24 20:51:15 +00:00
* refactor(plugins): trim activation and contract exports * test(plugins): restore fixture cleanup * refactor(plugins): trim install and loader exports * test(plugins): fully reset loader caches * refactor(plugins): trim metadata and catalog exports * test(plugins): preserve catalog trust coverage * refactor(plugins): trim provider and plugin exports * refactor(plugins): trim runtime and tool exports * test(plugins): update dead-export consumers * test(plugins): remove empty dead-export suites * refactor(plugins): align exports with split registry * refactor(plugins): trim drifted loader exports * style(plugins): format test fixtures * refactor(scripts): use supported plugin APIs * refactor(plugins): finish dead export cleanup * chore(deadcode): refresh export baseline * test(cli): mock production memory state * chore(deadcode): sync latest export baseline * fix(tests): keep plugin fixtures inside core * chore(deadcode): refresh rebased export baseline * chore(deadcode): sync current ratchets * fix(plugins): retain reserved slot invariant * fix(plugins): preserve dead-export invariants * test(plugins): use neutral catalog query fixture * test(plugins): satisfy catalog lint * test(plugins): preserve integrity drift coverage * fix(ci): register skill experience live proof
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
getMemoryCapabilityRegistration,
|
|
registerMemoryCapability,
|
|
} from "./memory-state.test-fixtures.js";
|
|
import {
|
|
createPluginRegistrationTransaction,
|
|
type PluginProcessGlobalState,
|
|
restorePluginProcessGlobalState,
|
|
snapshotPluginProcessGlobalState,
|
|
} from "./plugin-registration-transaction.js";
|
|
import { createEmptyPluginRegistry } from "./registry-empty.js";
|
|
|
|
describe("plugin registration transaction", () => {
|
|
let initialProcessGlobalState: PluginProcessGlobalState;
|
|
|
|
beforeEach(() => {
|
|
initialProcessGlobalState = snapshotPluginProcessGlobalState();
|
|
});
|
|
|
|
afterEach(() => {
|
|
restorePluginProcessGlobalState(initialProcessGlobalState);
|
|
});
|
|
|
|
it("rolls back registry writes and restores prior process-global capability state", () => {
|
|
const registry = createEmptyPluginRegistry();
|
|
const activePromptBuilder = () => ["active"];
|
|
const failedResolver = () => "failed";
|
|
const rollbackGlobalSideEffects = vi.fn();
|
|
registerMemoryCapability("active-memory", { promptBuilder: activePromptBuilder });
|
|
|
|
const transaction = createPluginRegistrationTransaction({
|
|
registry,
|
|
rollbackGlobalSideEffects,
|
|
});
|
|
registry.hostedMediaResolvers.push({
|
|
pluginId: "failed-plugin",
|
|
resolver: failedResolver,
|
|
source: "failed-plugin",
|
|
});
|
|
registry.gatewayHandlers.failed = async () => {};
|
|
registerMemoryCapability("failed-memory", { promptBuilder: () => ["failed"] });
|
|
|
|
transaction.rollback();
|
|
|
|
expect(rollbackGlobalSideEffects).toHaveBeenCalledOnce();
|
|
expect(registry.hostedMediaResolvers).toStrictEqual([]);
|
|
expect(registry.gatewayHandlers).toStrictEqual({});
|
|
expect(getMemoryCapabilityRegistration()).toEqual({
|
|
pluginId: "active-memory",
|
|
capability: { promptBuilder: activePromptBuilder },
|
|
});
|
|
});
|
|
|
|
it("keeps snapshot registry writes while restoring globals for non-activating commits", () => {
|
|
const registry = createEmptyPluginRegistry();
|
|
const activePromptBuilder = () => ["active"];
|
|
const snapshotResolver = () => "snapshot";
|
|
registerMemoryCapability("active-memory", { promptBuilder: activePromptBuilder });
|
|
|
|
const transaction = createPluginRegistrationTransaction({ registry });
|
|
registry.hostedMediaResolvers.push({
|
|
pluginId: "snapshot-plugin",
|
|
resolver: snapshotResolver,
|
|
source: "snapshot-plugin",
|
|
});
|
|
registerMemoryCapability("snapshot-memory", { promptBuilder: () => ["snapshot"] });
|
|
|
|
transaction.commit({ activate: false });
|
|
|
|
expect(registry.hostedMediaResolvers).toEqual([
|
|
{
|
|
pluginId: "snapshot-plugin",
|
|
resolver: snapshotResolver,
|
|
source: "snapshot-plugin",
|
|
},
|
|
]);
|
|
expect(getMemoryCapabilityRegistration()).toEqual({
|
|
pluginId: "active-memory",
|
|
capability: { promptBuilder: activePromptBuilder },
|
|
});
|
|
});
|
|
});
|