test: add OpenClaw adapter state-file tests / 新增 OpenClaw adapter state-file 測試
This commit is contained in:
38
tests/openclaw-adapter.test.mjs
Normal file
38
tests/openclaw-adapter.test.mjs
Normal 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)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user