test: reuse plugin session key surfaces

This commit is contained in:
Gustavo Madeira Santana
2026-03-31 19:22:42 -04:00
parent 28c73f06da
commit 8ca31b6241

View File

@@ -1,51 +1,24 @@
import { loadBundledPluginPublicSurfaceSync } from "./bundled-plugin-public-surface.js";
import { createTestRegistry } from "./channel-plugins.js";
function parseTelegramTopicConversation(rawId: string) {
const match = /^(-?\d+):topic:(\d+)$/i.exec(rawId.trim());
if (!match) {
return null;
}
return {
id: match[1],
threadId: match[2],
parentConversationCandidates: [match[1]],
};
type SessionConversationSurface = {
resolveSessionConversation?: (params: { kind: "group" | "channel"; rawId: string }) => {
id: string;
threadId?: string | null;
baseConversationId?: string | null;
parentConversationCandidates?: string[];
} | null;
};
function loadSessionConversationSurface(pluginId: string) {
return loadBundledPluginPublicSurfaceSync<SessionConversationSurface>({
pluginId,
artifactBasename: "session-key-api.js",
}).resolveSessionConversation;
}
function resolveFeishuConversation(rawId: string) {
const trimmed = rawId.trim();
if (!trimmed) {
return null;
}
const topicSenderMatch = /^(.+):topic:([^:]+):sender:([^:]+)$/i.exec(trimmed);
if (topicSenderMatch) {
const [, chatId, topicId, senderId] = topicSenderMatch;
return {
id: `${chatId}:topic:${topicId}:sender:${senderId}`,
parentConversationCandidates: [`${chatId}:topic:${topicId}`, chatId],
};
}
const topicMatch = /^(.+):topic:([^:]+)$/i.exec(trimmed);
if (topicMatch) {
const [, chatId, topicId] = topicMatch;
return {
id: `${chatId}:topic:${topicId}`,
parentConversationCandidates: [chatId],
};
}
const senderMatch = /^(.+):sender:([^:]+)$/i.exec(trimmed);
if (senderMatch) {
const [, chatId, senderId] = senderMatch;
return {
id: `${chatId}:sender:${senderId}`,
parentConversationCandidates: [chatId],
};
}
return {
id: trimmed,
parentConversationCandidates: [],
};
}
const resolveTelegramSessionConversation = loadSessionConversationSurface("telegram");
const resolveFeishuSessionConversation = loadSessionConversationSurface("feishu");
export function createSessionConversationTestRegistry() {
return createTestRegistry([
@@ -130,8 +103,7 @@ export function createSessionConversationTestRegistry() {
capabilities: { chatTypes: ["direct", "group", "thread"] },
messaging: {
normalizeTarget: (raw: string) => raw.replace(/^group:/, ""),
resolveSessionConversation: ({ rawId }: { rawId: string }) =>
parseTelegramTopicConversation(rawId),
resolveSessionConversation: resolveTelegramSessionConversation,
},
config: {
listAccountIds: () => ["default"],
@@ -154,8 +126,7 @@ export function createSessionConversationTestRegistry() {
capabilities: { chatTypes: ["direct", "group", "thread"] },
messaging: {
normalizeTarget: (raw: string) => raw.replace(/^group:/, ""),
resolveSessionConversation: ({ rawId }: { rawId: string }) =>
resolveFeishuConversation(rawId),
resolveSessionConversation: resolveFeishuSessionConversation,
},
config: {
listAccountIds: () => ["default"],