mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-24 02:41:12 +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
85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
/** Verifies hook callbacks receive agent context and scoped plugin metadata. */
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildAgentHookContextChannelFields,
|
|
buildAgentHookContextIdentityFields,
|
|
} from "./hook-agent-context.js";
|
|
|
|
describe("buildAgentHookContextChannelFields", () => {
|
|
it("keeps provider and conversation id separate", () => {
|
|
expect(
|
|
buildAgentHookContextChannelFields({
|
|
sessionKey: "agent:main:discord:channel:c1",
|
|
messageChannel: "discord",
|
|
messageProvider: "discord",
|
|
senderId: "user-123",
|
|
}),
|
|
).toEqual({
|
|
channel: "discord",
|
|
messageProvider: "discord",
|
|
channelId: "c1",
|
|
chatId: "c1",
|
|
senderId: "user-123",
|
|
});
|
|
});
|
|
|
|
it("uses the provider as channel when message channel is a target id", () => {
|
|
expect(
|
|
buildAgentHookContextChannelFields({
|
|
messageChannel: "channel:1472750640760623226",
|
|
messageProvider: "discord",
|
|
}),
|
|
).toEqual({
|
|
channel: "discord",
|
|
messageProvider: "discord",
|
|
channelId: "1472750640760623226",
|
|
chatId: "1472750640760623226",
|
|
senderId: undefined,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("buildAgentHookContextIdentityFields", () => {
|
|
it("mirrors flat sender and chat ids into channel-owned context", () => {
|
|
expect(
|
|
buildAgentHookContextIdentityFields({
|
|
senderId: "open-id-1",
|
|
chatId: "chat-1",
|
|
}),
|
|
).toEqual({
|
|
senderId: "open-id-1",
|
|
chatId: "chat-1",
|
|
channelContext: {
|
|
sender: { id: "open-id-1" },
|
|
chat: { id: "chat-1" },
|
|
},
|
|
});
|
|
});
|
|
|
|
it("preserves plugin-augmented channel fields while keeping id compatible", () => {
|
|
expect(
|
|
buildAgentHookContextIdentityFields({
|
|
senderId: "open-id-1",
|
|
channelContext: {
|
|
sender: { id: "stale-id", userId: "user-1" } as { id?: string; userId: string },
|
|
},
|
|
}),
|
|
).toEqual({
|
|
senderId: "open-id-1",
|
|
channelContext: {
|
|
sender: { id: "open-id-1", userId: "user-1" },
|
|
},
|
|
});
|
|
});
|
|
|
|
it("omits identity fields for system-originated triggers", () => {
|
|
expect(
|
|
buildAgentHookContextIdentityFields({
|
|
trigger: "cron",
|
|
senderId: "open-id-1",
|
|
chatId: "chat-1",
|
|
}),
|
|
).toEqual({});
|
|
});
|
|
});
|