mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:00:42 +00:00
fix(hooks): avoid stale thread ownership startup fallback
This commit is contained in:
@@ -211,6 +211,32 @@ describe("thread-ownership plugin", () => {
|
||||
expect(globalThis.fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not fall back to startup allowlists when live plugin config is removed", async () => {
|
||||
api.pluginConfig = { abTestChannels: ["C999"] };
|
||||
register.register(api as unknown as OpenClawPluginApi);
|
||||
vi.mocked(globalThis.fetch).mockResolvedValue(
|
||||
new Response(JSON.stringify({ owner: "test-agent" }), { status: 200 }),
|
||||
);
|
||||
|
||||
const result = await hooks.message_sending(
|
||||
{
|
||||
content: "hello",
|
||||
replyToId: "1234.5678",
|
||||
to: "C123",
|
||||
},
|
||||
{ channelId: "slack", conversationId: "C123" },
|
||||
);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(globalThis.fetch).toHaveBeenCalledWith(
|
||||
"http://localhost:8750/api/v1/ownership/C123/1234.5678",
|
||||
expect.objectContaining({
|
||||
method: "POST",
|
||||
body: JSON.stringify({ agent_id: "test-agent" }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("cancels when thread owned by another agent", async () => {
|
||||
vi.mocked(globalThis.fetch).mockResolvedValue(
|
||||
new Response(JSON.stringify({ owner: "other-agent" }), { status: 409 }),
|
||||
|
||||
@@ -83,11 +83,14 @@ export default definePluginEntry({
|
||||
description: "Slack thread claim coordination for multi-agent setups",
|
||||
register(api: OpenClawPluginApi) {
|
||||
const resolveCurrentState = () => {
|
||||
const currentConfig = api.runtime.config?.loadConfig?.() ?? api.config;
|
||||
const runtimeConfigAvailable = typeof api.runtime.config?.loadConfig === "function";
|
||||
const currentConfig = runtimeConfigAvailable
|
||||
? (api.runtime.config.loadConfig() ?? api.config)
|
||||
: api.config;
|
||||
const livePluginCfg = resolvePluginConfigObject(currentConfig, "thread-ownership");
|
||||
const pluginCfg = isThreadOwnershipConfig(livePluginCfg)
|
||||
? livePluginCfg
|
||||
: isThreadOwnershipConfig(api.pluginConfig)
|
||||
: !runtimeConfigAvailable && isThreadOwnershipConfig(api.pluginConfig)
|
||||
? api.pluginConfig
|
||||
: {};
|
||||
return {
|
||||
|
||||
@@ -70,7 +70,8 @@ const BUNDLED_LIVE_CONFIG_HOOK_GUARDS = {
|
||||
],
|
||||
"extensions/thread-ownership/index.ts": [
|
||||
'resolvePluginConfigObject(currentConfig, "thread-ownership")',
|
||||
"api.runtime.config?.loadConfig?.() ?? api.config",
|
||||
'typeof api.runtime.config?.loadConfig === "function"',
|
||||
"api.runtime.config.loadConfig() ?? api.config",
|
||||
],
|
||||
} as const satisfies Record<string, readonly string[]>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user