test: add OpenClaw adapter state-file tests / 新增 OpenClaw adapter state-file 測試

This commit is contained in:
Alice (OpenClaw)
2026-05-13 11:55:27 +08:00
parent 73a6da8d12
commit 900ea7b93f

View File

@@ -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)
})