Files
reply-end-controls/tests/openclaw-adapter.test.mjs

39 lines
1.3 KiB
JavaScript

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