mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-19 09:01:39 -06:00
28630a9a65
* feat(memory): add provenance and recall metadata to the memory index * feat(memory): provenance-gated promotion and capture hygiene * feat(dreaming): LLM consolidation with deterministic gates, on by default * feat(active-memory): deterministic recall lane with escalation default * feat(memory): user model file and standing intents * docs(memory): document the memory architecture * fix(memory): live-QA fixes — metadata writers, provenance classes, intent scope, claim accumulation
87 lines
2.3 KiB
TypeScript
87 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",
|
|
agentAccountId: "work",
|
|
senderId: "user-123",
|
|
}),
|
|
).toEqual({
|
|
channel: "discord",
|
|
accountId: "work",
|
|
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({});
|
|
});
|
|
});
|