Files
sh c8f20bcc91 core, libs: configurable queue size, library fixes (#7542)
* core: add chat_migrate_init_queue FFI export

* bots: fix BadgeServiceErrorCode API type

* nodejs: pass required command fields

* nodejs: fix migration error types

* nodejs: install libsimplex from SIMPLEX_LIBS_DIR

* nodejs: add queue size option

* nodejs: regenerate docs

* python: add queue size option

* bots: pass incognito in APIConnect

* nodejs: accept documented success responses

* python: accept documented success responses

* nodejs: dispatch each bot message once

* nodejs: fix startChat events loop lifecycle

* nodejs, python: parse multi-line bot commands

* nodejs: fix file buffer handling in addon

* nodejs: keep events loop when chat stop fails

* python: fix send_and_wait race, load lib off loop

* python: make queue size export optional

* nodejs: receive events on a dedicated thread

* nodejs: release haskell thread after receive

* python: receive on a dedicated thread per chat

* python: test receive shutdown order

* nodejs: one receive thread per chat controller

* nodejs: harden receiver shutdown and tests

* nodejs: stop chat before closing store

* python: stop chat before closing store

* nodejs, python: harden close regression and retry

* python: free results with ucrt on windows

* nodejs: enable c++ exceptions on mac and windows
2026-09-19 12:18:46 +01:00

42 lines
1.5 KiB
TypeScript

import {T} from "@simplex-chat/types"
import {ciBotCommand} from "../src/util"
function rcvText(text: string): T.ChatItem {
return {content: {type: "rcvMsgContent", msgContent: {type: "text", text}}} as T.ChatItem
}
describe("ciBotCommand", () => {
it("parses a command at the start of the message", () => {
expect(ciBotCommand(rcvText("/grok hello"))).toEqual({keyword: "grok", params: "hello"})
})
it("returns undefined for a slash in the middle of a word", () => {
expect(ciBotCommand(rcvText("What follow/read blog posts?"))).toBeUndefined()
})
it("returns undefined for a slash after a space", () => {
expect(ciBotCommand(rcvText("see /home for details"))).toBeUndefined()
})
it("strips leading whitespace before matching", () => {
expect(ciBotCommand(rcvText(" /grok ask this"))).toEqual({keyword: "grok", params: "ask this"})
})
it("returns command with empty params when only the keyword is present", () => {
expect(ciBotCommand(rcvText("/team"))).toEqual({keyword: "team", params: ""})
})
it("returns undefined for plain text without slash", () => {
expect(ciBotCommand(rcvText("hello there"))).toBeUndefined()
})
it("returns undefined for non-text chat item content", () => {
const ci = {content: {type: "rcvDeleted"}} as T.ChatItem
expect(ciBotCommand(ci)).toBeUndefined()
})
it("keeps multi-line params", () => {
expect(ciBotCommand(rcvText("/review line1\nline2"))).toEqual({keyword: "review", params: "line1\nline2"})
})
})