|
1 | | -import { describe, expect, it } from "vitest"; |
| 1 | +import fs from "node:fs"; |
| 2 | +import os from "node:os"; |
| 3 | +import path from "node:path"; |
| 4 | +import type { OpenKeyedStoreOptions } from "openclaw/plugin-sdk/plugin-state-runtime"; |
| 5 | +import { |
| 6 | + createPluginStateSyncKeyedStoreForTests, |
| 7 | + resetPluginStateStoreForTests, |
| 8 | +} from "openclaw/plugin-sdk/plugin-state-test-runtime"; |
| 9 | +import { createPluginRuntimeMock } from "openclaw/plugin-sdk/plugin-test-runtime"; |
| 10 | +import { defaultRuntime } from "openclaw/plugin-sdk/runtime"; |
| 11 | +import { afterEach, beforeEach, describe, expect, it } from "vitest"; |
| 12 | +import { generateIdentity } from "../protocol/index.js"; |
| 13 | +import { reefPlugin } from "./channel.js"; |
| 14 | +import { resolveReefConfig } from "./config-schema.js"; |
2 | 15 | import { resolveReefInboundDispatchContent } from "./inbound.js"; |
| 16 | +import { setReefRuntime } from "./runtime.js"; |
| 17 | +import { openReefTrustStore } from "./trust-store.js"; |
3 | 18 |
|
4 | 19 | describe("Reef inbound dispatch content", () => { |
5 | 20 | it("keeps provenance model-visible without storing it in the transcript body", () => { |
@@ -41,3 +56,50 @@ describe("Reef inbound dispatch content", () => { |
41 | 56 | }); |
42 | 57 | }); |
43 | 58 | }); |
| 59 | + |
| 60 | +describe("Reef conversation directory", () => { |
| 61 | + let stateDir = ""; |
| 62 | + |
| 63 | + beforeEach(() => { |
| 64 | + resetPluginStateStoreForTests(); |
| 65 | + // openclaw-temp-dir: allow Reef directory tests need an on-disk state root; afterEach removes it. |
| 66 | + stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "reef-directory-")); |
| 67 | + const runtime = createPluginRuntimeMock(); |
| 68 | + runtime.state.openSyncKeyedStore = <T>(options: OpenKeyedStoreOptions) => |
| 69 | + createPluginStateSyncKeyedStoreForTests<T>("reef", { |
| 70 | + ...options, |
| 71 | + env: { OPENCLAW_STATE_DIR: stateDir }, |
| 72 | + }); |
| 73 | + setReefRuntime(runtime); |
| 74 | + const identity = generateIdentity(); |
| 75 | + openReefTrustStore(runtime, resolveReefConfig({ channels: { reef: { handle: "clawd" } } })).set( |
| 76 | + "molty", |
| 77 | + { |
| 78 | + autonomy: "bounded", |
| 79 | + ed25519PublicKey: identity.signing.publicKey, |
| 80 | + x25519PublicKey: identity.encryption.publicKey, |
| 81 | + keyEpoch: 1, |
| 82 | + safetyNumberChanged: false, |
| 83 | + approvedAt: 1_752_537_600_000, |
| 84 | + }, |
| 85 | + ); |
| 86 | + }); |
| 87 | + |
| 88 | + afterEach(() => { |
| 89 | + resetPluginStateStoreForTests(); |
| 90 | + fs.rmSync(stateDir, { recursive: true, force: true }); |
| 91 | + }); |
| 92 | + |
| 93 | + it("exposes locally trusted peers as routable directory entries", async () => { |
| 94 | + const cfg = { channels: { reef: { handle: "clawd" } } }; |
| 95 | + await expect( |
| 96 | + reefPlugin.directory?.listPeers?.({ |
| 97 | + cfg, |
| 98 | + accountId: "default", |
| 99 | + query: "@molty", |
| 100 | + limit: 10, |
| 101 | + runtime: defaultRuntime, |
| 102 | + }), |
| 103 | + ).resolves.toEqual([{ kind: "user", id: "molty", name: "@molty's agent", handle: "@molty" }]); |
| 104 | + }); |
| 105 | +}); |
0 commit comments