mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-31 08:13:11 +03:00
28 lines
791 B
TypeScript
28 lines
791 B
TypeScript
import { afterEach, describe, expect, test } from "bun:test"
|
|
import { mkdtemp, readFile, rm } from "node:fs/promises"
|
|
import { tmpdir } from "node:os"
|
|
import { join } from "node:path"
|
|
|
|
import { rememberChat } from "./session-state"
|
|
|
|
describe("TUI session state", () => {
|
|
let directory = ""
|
|
|
|
afterEach(async () => {
|
|
if (directory) await rm(directory, { recursive: true, force: true })
|
|
directory = ""
|
|
})
|
|
|
|
test("atomically remembers the last attached gateway chat", async () => {
|
|
directory = await mkdtemp(join(tmpdir(), "nanobot-tui-state-"))
|
|
const path = join(directory, "nested", "state.json")
|
|
|
|
await rememberChat(path, "chat-123")
|
|
|
|
expect(JSON.parse(await readFile(path, "utf8"))).toEqual({
|
|
schema_version: 1,
|
|
chat_id: "chat-123",
|
|
})
|
|
})
|
|
})
|