From 900ea7b93fb5a5c669cccaf01ba2a3f52899cfb9 Mon Sep 17 00:00:00 2001 From: "Alice (OpenClaw)" Date: Wed, 13 May 2026 11:55:27 +0800 Subject: [PATCH] =?UTF-8?q?test:=20add=20OpenClaw=20adapter=20state-file?= =?UTF-8?q?=20tests=20/=20=E6=96=B0=E5=A2=9E=20OpenClaw=20adapter=20state-?= =?UTF-8?q?file=20=E6=B8=AC=E8=A9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/openclaw-adapter.test.mjs | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/openclaw-adapter.test.mjs diff --git a/tests/openclaw-adapter.test.mjs b/tests/openclaw-adapter.test.mjs new file mode 100644 index 0000000..33d3a83 --- /dev/null +++ b/tests/openclaw-adapter.test.mjs @@ -0,0 +1,38 @@ +import test from "node:test" +import assert from "node:assert/strict" +import fs from "node:fs" +import os from "node:os" +import path from "node:path" + +import { persistOpenClawReplyEndState, readOpenClawReplyEndState } from "../src/adapters/openclaw-state-file.ts" + +test("persistOpenClawReplyEndState writes normalized callback state to file-backed store", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "reply-end-openclaw-")) + + const stateMap = persistOpenClawReplyEndState(tempDir, { + choice: "stop", + conversationId: "telegram:864811879", + sessionKey: "agent:main:main", + sourceMessageId: "36", + sourceCallbackId: "cb-stop-1", + channel: "telegram", + timestamp: "2026-05-13T02:53:18.065Z", + }) + + assert.equal(stateMap["telegram:864811879"].lastChoice, "stop") + + const loaded = readOpenClawReplyEndState(tempDir, "telegram:864811879") + assert.deepEqual(loaded, { + lastChoice: "stop", + lastChoiceAt: "2026-05-13T02:53:18.065Z", + sourceMessageId: "36", + sourceCallbackId: "cb-stop-1", + active: true, + }) +}) + +test("readOpenClawReplyEndState returns null when conversation does not exist", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "reply-end-openclaw-")) + const loaded = readOpenClawReplyEndState(tempDir, "telegram:missing") + assert.equal(loaded, null) +})