|
| 1 | +import path from "node:path"; |
| 2 | +import { onTestFinished, vi } from "vitest"; |
| 3 | +import { createTempDirTracker } from "../../test/helpers/temp-dir.js"; |
| 4 | +import { |
| 5 | + beginConversationDeliveryOperation, |
| 6 | + getConversationDeliveryOperation, |
| 7 | + markConversationDeliveryQueued, |
| 8 | + markConversationDeliverySent, |
| 9 | + markConversationDeliverySuppressed, |
| 10 | +} from "../config/sessions/conversation-delivery-store.js"; |
| 11 | +import { registerConversationAddresses } from "../config/sessions/conversation-registry.js"; |
| 12 | +import { buildConversationRef } from "../routing/conversation-ref.js"; |
| 13 | +import { closeOpenClawAgentDatabaseByPath } from "../state/openclaw-agent-db.js"; |
| 14 | + |
| 15 | +const address = { |
| 16 | + channel: "reef", |
| 17 | + accountId: "default", |
| 18 | + kind: "direct" as const, |
| 19 | + peerId: "molty", |
| 20 | +}; |
| 21 | + |
| 22 | +export const conversation = { |
| 23 | + ...address, |
| 24 | + conversationRef: buildConversationRef(address), |
| 25 | + target: "reef:molty", |
| 26 | + sessionId: "reef-session", |
| 27 | + sessionKey: "agent:main:reef:direct:molty", |
| 28 | + role: "participant" as const, |
| 29 | + firstSeenAt: 100, |
| 30 | + lastSeenAt: 200, |
| 31 | +}; |
| 32 | + |
| 33 | +export function createConversationDeliveryTestStore(agentId = "main") { |
| 34 | + const dirs = createTempDirTracker(); |
| 35 | + const agentDir = path.join(dirs.make("openclaw-gateway-conversation-"), "agents", agentId); |
| 36 | + const scope = { agentId, storePath: path.join(agentDir, "sessions", "sessions.json") }; |
| 37 | + onTestFinished(() => { |
| 38 | + closeOpenClawAgentDatabaseByPath(path.join(agentDir, "agent", "openclaw-agent.sqlite")); |
| 39 | + dirs.cleanup(); |
| 40 | + }); |
| 41 | + registerConversationAddresses(scope, [{ ...conversation, deliveryTarget: conversation.target }]); |
| 42 | + return { |
| 43 | + scope, |
| 44 | + config: { session: { store: scope.storePath } }, |
| 45 | + beginOperation: vi.fn(beginConversationDeliveryOperation), |
| 46 | + getOperation: vi.fn(getConversationDeliveryOperation), |
| 47 | + markQueued: vi.fn(markConversationDeliveryQueued), |
| 48 | + markSent: vi.fn(markConversationDeliverySent), |
| 49 | + markSuppressed: vi.fn(markConversationDeliverySuppressed), |
| 50 | + }; |
| 51 | +} |
0 commit comments