Compare commits
12 Commits
138df60661
...
integratio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27ad93d749
|
||
|
|
f880795b44
|
||
| a158ee385f | |||
|
|
2da7cc4450
|
||
|
|
3af95235e6
|
||
|
|
5d390ee9f3
|
||
|
|
7f7981d6cd
|
||
|
|
ae190cc421
|
||
|
|
ae44cc947b
|
||
|
|
a3ebca0bb2
|
||
|
|
8fa79932d6
|
||
|
|
9719d9203c
|
234
Cargo.lock
generated
234
Cargo.lock
generated
@@ -17,6 +17,15 @@ version = "2.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "android_system_properties"
|
name = "android_system_properties"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@@ -90,7 +99,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -172,6 +181,12 @@ version = "1.10.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
|
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cargo-husky"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b02b629252fe8ef6460461409564e2c21d0c8e77e0944f3d189ff06c4e932ad"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.43"
|
version = "1.2.43"
|
||||||
@@ -237,7 +252,7 @@ dependencies = [
|
|||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -402,7 +417,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"strsim",
|
"strsim",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -413,7 +428,7 @@ checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core",
|
"darling_core",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -452,7 +467,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -463,7 +478,7 @@ checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -506,7 +521,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -518,24 +533,6 @@ dependencies = [
|
|||||||
"const-random",
|
"const-random",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dotenvy"
|
|
||||||
version = "0.15.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dotenvy_macro"
|
|
||||||
version = "0.15.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cb0235d912a8c749f4e0c9f18ca253b4c28cfefc1d2518096016d6e3230b6424"
|
|
||||||
dependencies = [
|
|
||||||
"dotenvy",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dyn-clone"
|
name = "dyn-clone"
|
||||||
version = "1.0.20"
|
version = "1.0.20"
|
||||||
@@ -773,7 +770,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -876,6 +873,12 @@ version = "0.32.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
|
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glob"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.12.3"
|
version = "0.12.3"
|
||||||
@@ -1398,6 +1401,18 @@ dependencies = [
|
|||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nix"
|
||||||
|
version = "0.30.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cfg-if",
|
||||||
|
"cfg_aliases",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nom"
|
name = "nom"
|
||||||
version = "7.1.3"
|
version = "7.1.3"
|
||||||
@@ -1476,7 +1491,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1596,7 +1611,7 @@ dependencies = [
|
|||||||
"pest_meta",
|
"pest_meta",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1626,7 +1641,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1684,6 +1699,15 @@ dependencies = [
|
|||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-crate"
|
||||||
|
version = "3.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983"
|
||||||
|
dependencies = [
|
||||||
|
"toml_edit 0.23.7",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.103"
|
version = "1.0.103"
|
||||||
@@ -1838,9 +1862,44 @@ checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.12.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "relative-path"
|
||||||
|
version = "1.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.12.24"
|
version = "0.12.24"
|
||||||
@@ -1917,15 +1976,19 @@ name = "robotnik"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"better-panic",
|
"better-panic",
|
||||||
|
"cargo-husky",
|
||||||
"clap",
|
"clap",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"config",
|
"config",
|
||||||
"directories",
|
"directories",
|
||||||
"dotenvy_macro",
|
|
||||||
"futures",
|
"futures",
|
||||||
"genai",
|
"genai",
|
||||||
"human-panic",
|
"human-panic",
|
||||||
"irc",
|
"irc",
|
||||||
|
"nix",
|
||||||
|
"rstest",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
@@ -1943,6 +2006,36 @@ dependencies = [
|
|||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rstest"
|
||||||
|
version = "0.24.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "03e905296805ab93e13c1ec3a03f4b6c4f35e9498a3d5fa96dc626d22c03cd89"
|
||||||
|
dependencies = [
|
||||||
|
"futures-timer",
|
||||||
|
"futures-util",
|
||||||
|
"rstest_macros",
|
||||||
|
"rustc_version",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rstest_macros"
|
||||||
|
version = "0.24.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ef0053bbffce09062bee4bcc499b0fbe7a57b879f1efe088d6d8d4c7adcdef9b"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"glob",
|
||||||
|
"proc-macro-crate",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"regex",
|
||||||
|
"relative-path",
|
||||||
|
"rustc_version",
|
||||||
|
"syn",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust-ini"
|
name = "rust-ini"
|
||||||
version = "0.21.3"
|
version = "0.21.3"
|
||||||
@@ -1965,6 +2058,15 @@ version = "2.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
|
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc_version"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
|
||||||
|
dependencies = [
|
||||||
|
"semver",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
@@ -2087,6 +2189,12 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "1.0.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.228"
|
version = "1.0.228"
|
||||||
@@ -2126,7 +2234,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2200,7 +2308,7 @@ dependencies = [
|
|||||||
"darling",
|
"darling",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2229,15 +2337,6 @@ version = "1.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "signal-hook-registry"
|
|
||||||
version = "1.4.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.11"
|
version = "0.4.11"
|
||||||
@@ -2278,17 +2377,6 @@ version = "2.6.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.109"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.108"
|
version = "2.0.108"
|
||||||
@@ -2317,7 +2405,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2359,7 +2447,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2370,7 +2458,7 @@ checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2456,9 +2544,7 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
"parking_lot",
|
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"signal-hook-registry",
|
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio-macros",
|
"tokio-macros",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
@@ -2472,7 +2558,7 @@ checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2528,7 +2614,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_spanned 0.6.9",
|
"serde_spanned 0.6.9",
|
||||||
"toml_datetime 0.6.11",
|
"toml_datetime 0.6.11",
|
||||||
"toml_edit",
|
"toml_edit 0.19.15",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2576,6 +2662,18 @@ dependencies = [
|
|||||||
"winnow 0.5.40",
|
"winnow 0.5.40",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_edit"
|
||||||
|
version = "0.23.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6485ef6d0d9b5d0ec17244ff7eb05310113c3f316f2d14200d4de56b3cb98f8d"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap 2.12.0",
|
||||||
|
"toml_datetime 0.7.3",
|
||||||
|
"toml_parser",
|
||||||
|
"winnow 0.7.13",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_parser"
|
name = "toml_parser"
|
||||||
version = "1.0.4"
|
version = "1.0.4"
|
||||||
@@ -2655,7 +2753,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2882,7 +2980,7 @@ dependencies = [
|
|||||||
"bumpalo",
|
"bumpalo",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2958,7 +3056,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2969,7 +3067,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3221,7 +3319,7 @@ checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3242,7 +3340,7 @@ checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3262,7 +3360,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3302,5 +3400,5 @@ checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.108",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|||||||
43
Cargo.toml
43
Cargo.toml
@@ -4,17 +4,50 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# TODO: make this a dev and/or debug dependency later.
|
|
||||||
better-panic = "0.3.0"
|
better-panic = "0.3.0"
|
||||||
clap = { version = "4.5", features = [ "derive" ] }
|
|
||||||
color-eyre = "0.6.3"
|
color-eyre = "0.6.3"
|
||||||
config = { version = "0.15", features = [ "toml" ] }
|
|
||||||
directories = "6.0"
|
directories = "6.0"
|
||||||
dotenvy_macro = "0.15"
|
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
human-panic = "2.0"
|
human-panic = "2.0"
|
||||||
genai = "0.4.3"
|
genai = "0.4.3"
|
||||||
irc = "1.1"
|
irc = "1.1"
|
||||||
tokio = { version = "1", features = [ "full" ] }
|
serde_json = "1.0"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = "0.3"
|
tracing-subscriber = "0.3"
|
||||||
|
|
||||||
|
[dependencies.nix]
|
||||||
|
version = "0.30.1"
|
||||||
|
features = [ "fs" ]
|
||||||
|
|
||||||
|
[dependencies.clap]
|
||||||
|
version = "4.5"
|
||||||
|
features = [ "derive" ]
|
||||||
|
|
||||||
|
[dependencies.config]
|
||||||
|
version = "0.15"
|
||||||
|
features = [ "toml" ]
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
version = "1.0"
|
||||||
|
features = [ "derive" ]
|
||||||
|
|
||||||
|
[dependencies.tokio]
|
||||||
|
version = "1"
|
||||||
|
features = [ "io-util", "macros", "net", "rt-multi-thread", "sync" ]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
rstest = "0.24"
|
||||||
|
|
||||||
|
[dev-dependencies.cargo-husky]
|
||||||
|
version = "1"
|
||||||
|
features = [
|
||||||
|
"run-cargo-check",
|
||||||
|
"run-cargo-clippy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
strip = true
|
||||||
|
opt-level = "z"
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
panic = "abort"
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ style_edition = "2024"
|
|||||||
comment_width = 100
|
comment_width = 100
|
||||||
format_code_in_doc_comments = true
|
format_code_in_doc_comments = true
|
||||||
imports_granularity = "Crate"
|
imports_granularity = "Crate"
|
||||||
imports_layout = "Vertical"
|
imports_layout = "HorizontalVertical"
|
||||||
wrap_comments = true
|
wrap_comments = true
|
||||||
|
|||||||
52
src/chat.rs
52
src/chat.rs
@@ -1,27 +1,10 @@
|
|||||||
use color_eyre::{
|
use color_eyre::{Result, eyre::WrapErr};
|
||||||
Result,
|
|
||||||
eyre::{
|
|
||||||
OptionExt,
|
|
||||||
WrapErr,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
// Lots of namespace confusion potential
|
// Lots of namespace confusion potential
|
||||||
use crate::{
|
use crate::qna::LLMHandle;
|
||||||
commands,
|
|
||||||
qna::LLMHandle,
|
|
||||||
};
|
|
||||||
use config::Config as MainConfig;
|
use config::Config as MainConfig;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use irc::client::prelude::{
|
use irc::client::prelude::{Client as IRCClient, Command, Config as IRCConfig};
|
||||||
Client as IRCClient,
|
use tracing::{Level, event, instrument};
|
||||||
Command,
|
|
||||||
Config as IRCConfig,
|
|
||||||
};
|
|
||||||
use tracing::{
|
|
||||||
Level,
|
|
||||||
event,
|
|
||||||
instrument,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Chat {
|
pub struct Chat {
|
||||||
@@ -31,10 +14,7 @@ pub struct Chat {
|
|||||||
|
|
||||||
// Need: owners, channels, username, nick, server, password
|
// Need: owners, channels, username, nick, server, password
|
||||||
#[instrument]
|
#[instrument]
|
||||||
pub async fn new(
|
pub async fn new(settings: &MainConfig, handle: &LLMHandle) -> Result<Chat> {
|
||||||
settings: &MainConfig,
|
|
||||||
handle: &LLMHandle,
|
|
||||||
) -> Result<Chat> {
|
|
||||||
// Going to just assign and let the irc library handle errors for now, and
|
// Going to just assign and let the irc library handle errors for now, and
|
||||||
// add my own checking if necessary.
|
// add my own checking if necessary.
|
||||||
let port: u16 = settings.get("port")?;
|
let port: u16 = settings.get("port")?;
|
||||||
@@ -66,26 +46,22 @@ impl Chat {
|
|||||||
|
|
||||||
client.identify()?;
|
client.identify()?;
|
||||||
|
|
||||||
let outgoing = client
|
|
||||||
.outgoing()
|
|
||||||
.ok_or_eyre("Couldn't get outgoing irc sink.")?;
|
|
||||||
let mut stream = client.stream()?;
|
let mut stream = client.stream()?;
|
||||||
|
|
||||||
tokio::spawn(async move {
|
|
||||||
if let Err(e) = outgoing.await {
|
|
||||||
event!(Level::ERROR, "Failed to drive output: {}", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
while let Some(message) = stream.next().await.transpose()? {
|
while let Some(message) = stream.next().await.transpose()? {
|
||||||
if let Command::PRIVMSG(channel, message) = message.command
|
if let Command::PRIVMSG(channel, message) = message.command
|
||||||
&& message.starts_with("!gem")
|
&& message.starts_with("!gem")
|
||||||
{
|
{
|
||||||
let msg = self.llm_handle.send_request(message).await?;
|
let mut msg = self.llm_handle.send_request(&message).await?;
|
||||||
event!(Level::INFO, "Message received.");
|
event!(Level::INFO, "Asked: {}", message);
|
||||||
|
event!(Level::INFO, "Answered: {}", msg);
|
||||||
|
|
||||||
|
// Make it all one line.
|
||||||
|
msg.retain(|c| c != '\n' && c != '\r');
|
||||||
|
msg.truncate(500);
|
||||||
client
|
client
|
||||||
.send_privmsg(channel, msg)
|
.send_privmsg(&channel, msg)
|
||||||
.wrap_err("Couldn't send response to channel.")?;
|
.wrap_err("Could not send to {channel}")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
use color_eyre::Result;
|
|
||||||
use std::{
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Root {
|
|
||||||
path: PathBuf,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Root {
|
|
||||||
pub fn new(path: impl AsRef<Path>) -> Self {
|
|
||||||
Root {
|
|
||||||
path: path.as_ref().to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_command(cmd_string: impl AsRef<str>) -> Result<()> {
|
|
||||||
todo!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
src/event.rs
Normal file
14
src/event.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct Event {
|
||||||
|
message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Event {
|
||||||
|
pub fn new(msg: impl Into<String>) -> Self {
|
||||||
|
Self {
|
||||||
|
message: msg.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
293
src/event_manager.rs
Normal file
293
src/event_manager.rs
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
use std::{collections::VecDeque, path::Path, sync::Arc};
|
||||||
|
|
||||||
|
use color_eyre::Result;
|
||||||
|
//use nix::{NixPath, sys::stat, unistd::mkfifo};
|
||||||
|
use tokio::{
|
||||||
|
// fs::File,
|
||||||
|
io::AsyncWriteExt,
|
||||||
|
net::{
|
||||||
|
UnixListener,
|
||||||
|
UnixStream,
|
||||||
|
// unix::pipe::{self, Receiver},
|
||||||
|
},
|
||||||
|
sync::{RwLock, broadcast},
|
||||||
|
};
|
||||||
|
use tracing::{error, info};
|
||||||
|
|
||||||
|
use crate::event::Event;
|
||||||
|
|
||||||
|
// Hard coding for now. Maybe make this a parameter to new.
|
||||||
|
const EVENT_BUF_MAX: usize = 1000;
|
||||||
|
|
||||||
|
// Manager for communication with plugins.
|
||||||
|
pub struct EventManager {
|
||||||
|
announce: broadcast::Sender<String>, // Everything broadcasts here.
|
||||||
|
events: Arc<RwLock<VecDeque<String>>>, // Ring buffer.
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventManager {
|
||||||
|
pub fn new() -> Result<Self> {
|
||||||
|
let (announce, _) = broadcast::channel(100);
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
announce,
|
||||||
|
events: Arc::new(RwLock::new(VecDeque::<String>::new())),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn broadcast(&self, event: &Event) -> Result<()> {
|
||||||
|
let msg = serde_json::to_string(event)? + "\n";
|
||||||
|
|
||||||
|
let mut events = self.events.write().await;
|
||||||
|
|
||||||
|
if events.len() >= EVENT_BUF_MAX {
|
||||||
|
events.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
|
events.push_back(msg.clone());
|
||||||
|
drop(events);
|
||||||
|
|
||||||
|
let _ = self.announce.send(msg);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// NB: This assumes it has exclusive control of the FIFO.
|
||||||
|
// async fn start_fifo<P>(path: &P) -> Result<()>
|
||||||
|
// where
|
||||||
|
// P: AsRef<Path> + NixPath + ?Sized,
|
||||||
|
// {
|
||||||
|
// // Just delete the old FIFO if it exists.
|
||||||
|
// let _ = std::fs::remove_file(path);
|
||||||
|
// mkfifo(path, stat::Mode::S_IRWXU)?;
|
||||||
|
|
||||||
|
// Ok(())
|
||||||
|
// }
|
||||||
|
|
||||||
|
pub async fn start_listening(self: Arc<Self>, broadcast_path: impl AsRef<Path>) {
|
||||||
|
let listener = UnixListener::bind(broadcast_path).unwrap();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match listener.accept().await {
|
||||||
|
Ok((stream, _addr)) => {
|
||||||
|
info!("New broadcast subscriber");
|
||||||
|
// Spawn a new stream for the plugin. The loop
|
||||||
|
// runs recursively from there.
|
||||||
|
let broadcaster = Arc::clone(&self);
|
||||||
|
tokio::spawn(async move {
|
||||||
|
// send events.
|
||||||
|
let _ = broadcaster.send_events(stream).await;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Err(e) => error!("Accept error: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn send_events(&self, stream: UnixStream) -> Result<()> {
|
||||||
|
let mut writer = stream;
|
||||||
|
|
||||||
|
// Take care of history.
|
||||||
|
let events = self.events.read().await;
|
||||||
|
for event in events.iter() {
|
||||||
|
writer.write_all(event.as_bytes()).await?;
|
||||||
|
}
|
||||||
|
drop(events);
|
||||||
|
|
||||||
|
// Now just broadcast the new events.
|
||||||
|
let mut rx = self.announce.subscribe();
|
||||||
|
while let Ok(event) = rx.recv().await {
|
||||||
|
if writer.write_all(event.as_bytes()).await.is_err() {
|
||||||
|
// *click*
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use rstest::rstest;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_new_event_manager_has_empty_buffer() {
|
||||||
|
let manager = EventManager::new().unwrap();
|
||||||
|
let events = manager.events.read().await;
|
||||||
|
assert_eq!(events.len(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_broadcast_adds_event_to_buffer() {
|
||||||
|
let manager = EventManager::new().unwrap();
|
||||||
|
let event = Event::new("test message");
|
||||||
|
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
|
||||||
|
let events = manager.events.read().await;
|
||||||
|
assert_eq!(events.len(), 1);
|
||||||
|
assert!(events[0].contains("test message"));
|
||||||
|
assert!(events[0].ends_with('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_broadcast_serializes_event_as_json() {
|
||||||
|
let manager = EventManager::new().unwrap();
|
||||||
|
let event = Event::new("hello world");
|
||||||
|
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
|
||||||
|
let events = manager.events.read().await;
|
||||||
|
let stored = &events[0];
|
||||||
|
|
||||||
|
// Should be valid JSON
|
||||||
|
let parsed: serde_json::Value = serde_json::from_str(stored.trim()).unwrap();
|
||||||
|
assert_eq!(parsed["message"], "hello world");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[case(1)]
|
||||||
|
#[case(10)]
|
||||||
|
#[case(100)]
|
||||||
|
#[case(999)]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_buffer_holds_events_below_max(#[case] count: usize) {
|
||||||
|
let manager = EventManager::new().unwrap();
|
||||||
|
|
||||||
|
for i in 0..count {
|
||||||
|
let event = Event::new(format!("event {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let events = manager.events.read().await;
|
||||||
|
assert_eq!(events.len(), count);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_buffer_at_exactly_max_capacity() {
|
||||||
|
let manager = EventManager::new().unwrap();
|
||||||
|
|
||||||
|
// Fill to exactly EVENT_BUF_MAX (1000)
|
||||||
|
for i in 0..EVENT_BUF_MAX {
|
||||||
|
let event = Event::new(format!("event {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let events = manager.events.read().await;
|
||||||
|
assert_eq!(events.len(), EVENT_BUF_MAX);
|
||||||
|
assert!(events[0].contains("event 0"));
|
||||||
|
assert!(events[EVENT_BUF_MAX - 1].contains("event 999"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[case(1)]
|
||||||
|
#[case(10)]
|
||||||
|
#[case(100)]
|
||||||
|
#[case(500)]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_buffer_overflow_evicts_oldest_fifo(#[case] overflow: usize) {
|
||||||
|
let manager = EventManager::new().unwrap();
|
||||||
|
let total = EVENT_BUF_MAX + overflow;
|
||||||
|
|
||||||
|
// Broadcast more events than buffer can hold
|
||||||
|
for i in 0..total {
|
||||||
|
let event = Event::new(format!("event {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let events = manager.events.read().await;
|
||||||
|
|
||||||
|
// Buffer should still be at max capacity
|
||||||
|
assert_eq!(events.len(), EVENT_BUF_MAX);
|
||||||
|
|
||||||
|
// Oldest events (0 through overflow-1) should be evicted
|
||||||
|
// Buffer should contain events [overflow..total)
|
||||||
|
let first_event = &events[0];
|
||||||
|
let last_event = &events[EVENT_BUF_MAX - 1];
|
||||||
|
|
||||||
|
assert!(first_event.contains(&format!("event {}", overflow)));
|
||||||
|
assert!(last_event.contains(&format!("event {}", total - 1)));
|
||||||
|
|
||||||
|
// Verify the evicted events are NOT in the buffer
|
||||||
|
let buffer_string = events.iter().cloned().collect::<String>();
|
||||||
|
assert!(!buffer_string.contains(r#""message":"event 0""#));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_multiple_broadcasts_maintain_order() {
|
||||||
|
let manager = EventManager::new().unwrap();
|
||||||
|
let messages = vec!["first", "second", "third", "fourth", "fifth"];
|
||||||
|
|
||||||
|
for msg in &messages {
|
||||||
|
let event = Event::new(*msg);
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let events = manager.events.read().await;
|
||||||
|
assert_eq!(events.len(), messages.len());
|
||||||
|
|
||||||
|
for (i, expected) in messages.iter().enumerate() {
|
||||||
|
assert!(events[i].contains(expected));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_buffer_wraparound_maintains_newest_events() {
|
||||||
|
let manager = EventManager::new().unwrap();
|
||||||
|
|
||||||
|
// Fill buffer completely
|
||||||
|
for i in 0..EVENT_BUF_MAX {
|
||||||
|
let event = Event::new(format!("old {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add 5 more events
|
||||||
|
for i in 0..5 {
|
||||||
|
let event = Event::new(format!("new {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let events = manager.events.read().await;
|
||||||
|
assert_eq!(events.len(), EVENT_BUF_MAX);
|
||||||
|
|
||||||
|
// First 5 old events should be gone
|
||||||
|
let buffer_string = events.iter().cloned().collect::<String>();
|
||||||
|
assert!(!buffer_string.contains(r#""message":"old 0""#));
|
||||||
|
assert!(!buffer_string.contains(r#""message":"old 4""#));
|
||||||
|
|
||||||
|
// But old 5 should still be there (now at the front)
|
||||||
|
assert!(events[0].contains("old 5"));
|
||||||
|
|
||||||
|
// New events should be at the end
|
||||||
|
assert!(events[EVENT_BUF_MAX - 5].contains("new 0"));
|
||||||
|
assert!(events[EVENT_BUF_MAX - 1].contains("new 4"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_concurrent_broadcasts_all_stored() {
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
let mut handles = vec![];
|
||||||
|
|
||||||
|
// Spawn 10 concurrent tasks, each broadcasting 10 events
|
||||||
|
for task_id in 0..10 {
|
||||||
|
let manager_clone = Arc::clone(&manager);
|
||||||
|
let handle = tokio::spawn(async move {
|
||||||
|
for i in 0..10 {
|
||||||
|
let event = Event::new(format!("task {} event {}", task_id, i));
|
||||||
|
manager_clone.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
handles.push(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for all tasks to complete
|
||||||
|
for handle in handles {
|
||||||
|
handle.await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let events = manager.events.read().await;
|
||||||
|
assert_eq!(events.len(), 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/ipc.rs
Normal file
26
src/ipc.rs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// Provides an IPC socket to communicate with other processes.
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use color_eyre::Result;
|
||||||
|
use tokio::net::UnixListener;
|
||||||
|
|
||||||
|
pub struct IPC {
|
||||||
|
listener: UnixListener,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IPC {
|
||||||
|
pub fn new(path: impl AsRef<Path>) -> Result<Self> {
|
||||||
|
let listener = UnixListener::bind(path)?;
|
||||||
|
Ok(Self { listener })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run(&self) -> Result<()> {
|
||||||
|
loop {
|
||||||
|
match self.listener.accept().await {
|
||||||
|
Ok((_stream, _addr)) => {}
|
||||||
|
Err(e) => return Err(e.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
85
src/lib.rs
Normal file
85
src/lib.rs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
// Robotnik libraries
|
||||||
|
|
||||||
|
use std::{os::unix::fs, sync::Arc};
|
||||||
|
|
||||||
|
use color_eyre::{Result, eyre::WrapErr};
|
||||||
|
use human_panic::setup_panic;
|
||||||
|
use tracing::{Level, info};
|
||||||
|
use tracing_subscriber::FmtSubscriber;
|
||||||
|
|
||||||
|
pub mod chat;
|
||||||
|
pub mod event;
|
||||||
|
pub mod event_manager;
|
||||||
|
pub mod ipc;
|
||||||
|
pub mod qna;
|
||||||
|
pub mod setup;
|
||||||
|
|
||||||
|
pub use event::Event;
|
||||||
|
pub use event_manager::EventManager;
|
||||||
|
pub use qna::LLMHandle;
|
||||||
|
|
||||||
|
const DEFAULT_INSTRUCT: &str =
|
||||||
|
"You are a shady, yet helpful IRC bot. You try to give responses that can
|
||||||
|
be sent in a single IRC response according to the specification. Keep answers to
|
||||||
|
500 characters or less.";
|
||||||
|
|
||||||
|
// NB: Everything should fail if logging doesn't start properly.
|
||||||
|
async fn init_logging() {
|
||||||
|
better_panic::install();
|
||||||
|
setup_panic!();
|
||||||
|
|
||||||
|
let subscriber = FmtSubscriber::builder()
|
||||||
|
.with_max_level(Level::TRACE)
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
tracing::subscriber::set_global_default(subscriber).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run() -> Result<()> {
|
||||||
|
init_logging().await;
|
||||||
|
info!("Starting up.");
|
||||||
|
|
||||||
|
let settings = setup::init().await.wrap_err("Failed to initialize.")?;
|
||||||
|
let config = settings.config;
|
||||||
|
|
||||||
|
// NOTE: Doing chroot this way might be impractical.
|
||||||
|
if let Ok(chroot_path) = config.get_string("chroot-dir") {
|
||||||
|
info!("Attempting to chroot to {}", chroot_path);
|
||||||
|
fs::chroot(&chroot_path)
|
||||||
|
.wrap_err_with(|| format!("Failed setting chroot '{}'", chroot_path))?;
|
||||||
|
std::env::set_current_dir("/").wrap_err("Couldn't change directory after chroot.")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let handle = qna::LLMHandle::new(
|
||||||
|
config.get_string("api-key").wrap_err("API missing.")?,
|
||||||
|
config
|
||||||
|
.get_string("base-url")
|
||||||
|
.wrap_err("base-url missing.")?,
|
||||||
|
config
|
||||||
|
.get_string("model")
|
||||||
|
.wrap_err("model string missing.")?,
|
||||||
|
config
|
||||||
|
.get_string("instruct")
|
||||||
|
.unwrap_or_else(|_| DEFAULT_INSTRUCT.to_string()),
|
||||||
|
)
|
||||||
|
.wrap_err("Couldn't initialize LLM handle.")?;
|
||||||
|
|
||||||
|
let ev_manager = Arc::new(EventManager::new()?);
|
||||||
|
let ev_manager_clone = Arc::clone(&ev_manager);
|
||||||
|
ev_manager_clone
|
||||||
|
.broadcast(&Event::new("Starting..."))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut c = chat::new(&config, &handle).await?;
|
||||||
|
|
||||||
|
tokio::select! {
|
||||||
|
_ = ev_manager_clone.start_listening("/tmp/robo.sock") => {
|
||||||
|
// Event listener ended
|
||||||
|
}
|
||||||
|
result = c.run() => {
|
||||||
|
result.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
73
src/main.rs
73
src/main.rs
@@ -1,75 +1,6 @@
|
|||||||
use color_eyre::{
|
use color_eyre::Result;
|
||||||
Result,
|
|
||||||
eyre::WrapErr,
|
|
||||||
};
|
|
||||||
use human_panic::setup_panic;
|
|
||||||
use std::os::unix::fs;
|
|
||||||
use tracing::{
|
|
||||||
Level,
|
|
||||||
info,
|
|
||||||
};
|
|
||||||
use tracing_subscriber::FmtSubscriber;
|
|
||||||
|
|
||||||
mod chat;
|
|
||||||
mod commands;
|
|
||||||
mod qna;
|
|
||||||
mod setup;
|
|
||||||
|
|
||||||
const DEFAULT_INSTRUCT: &str =
|
|
||||||
"You are a shady, yet helpful IRC bot. You try to give responses that can
|
|
||||||
be sent in a single IRC response according to the specification.";
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
// Some error sprucing.
|
robotnik::run().await
|
||||||
better_panic::install();
|
|
||||||
setup_panic!();
|
|
||||||
|
|
||||||
let subscriber = FmtSubscriber::builder()
|
|
||||||
.with_max_level(Level::TRACE)
|
|
||||||
.finish();
|
|
||||||
|
|
||||||
tracing::subscriber::set_global_default(subscriber)
|
|
||||||
.wrap_err("Failed to setup trace logging.")?;
|
|
||||||
|
|
||||||
info!("Starting");
|
|
||||||
|
|
||||||
let settings = setup::init().await.wrap_err("Failed to initialize.")?;
|
|
||||||
let config = settings.config;
|
|
||||||
|
|
||||||
// chroot if applicable.
|
|
||||||
if let Ok(chroot_path) = config.get_string("chroot-dir") {
|
|
||||||
info!("Attempting to chroot to {}", chroot_path);
|
|
||||||
fs::chroot(&chroot_path)
|
|
||||||
.wrap_err_with(|| format!("Failed setting chroot '{}'", chroot_path))?;
|
|
||||||
std::env::set_current_dir("/").wrap_err("Couldn't change directory after chroot.")?;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup root path for commands.
|
|
||||||
let cmd_root = if let Ok(command_path) = config.get_string("command-path") {
|
|
||||||
Some(commands::Root::new(command_path))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let handle = qna::LLMHandle::new(
|
|
||||||
config.get_string("api-key").wrap_err("API missing.")?,
|
|
||||||
config
|
|
||||||
.get_string("base-url")
|
|
||||||
.wrap_err("base-url missing.")?,
|
|
||||||
cmd_root,
|
|
||||||
config
|
|
||||||
.get_string("model")
|
|
||||||
.wrap_err("model string missing.")?,
|
|
||||||
config
|
|
||||||
.get_string("instruct")
|
|
||||||
.unwrap_or_else(|_| DEFAULT_INSTRUCT.to_string()),
|
|
||||||
)
|
|
||||||
.wrap_err("Couldn't initialize LLM handle.")?;
|
|
||||||
let mut c = chat::new(&config, &handle).await?;
|
|
||||||
|
|
||||||
c.run().await.unwrap();
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/qna.rs
21
src/qna.rs
@@ -1,19 +1,10 @@
|
|||||||
use crate::commands;
|
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use genai::{
|
use genai::{
|
||||||
Client,
|
Client,
|
||||||
ModelIden,
|
ModelIden,
|
||||||
chat::{
|
chat::{ChatMessage, ChatRequest, ChatStreamEvent, StreamChunk},
|
||||||
ChatMessage,
|
resolver::{AuthData, AuthResolver},
|
||||||
ChatRequest,
|
|
||||||
ChatStreamEvent,
|
|
||||||
StreamChunk,
|
|
||||||
},
|
|
||||||
resolver::{
|
|
||||||
AuthData,
|
|
||||||
AuthResolver,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
@@ -23,7 +14,6 @@ use tracing::info;
|
|||||||
pub struct LLMHandle {
|
pub struct LLMHandle {
|
||||||
chat_request: ChatRequest,
|
chat_request: ChatRequest,
|
||||||
client: Client,
|
client: Client,
|
||||||
cmd_root: Option<commands::Root>,
|
|
||||||
model: String,
|
model: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +21,6 @@ impl LLMHandle {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
api_key: String,
|
api_key: String,
|
||||||
_base_url: impl AsRef<str>,
|
_base_url: impl AsRef<str>,
|
||||||
cmd_root: Option<commands::Root>,
|
|
||||||
model: impl Into<String>,
|
model: impl Into<String>,
|
||||||
system_role: String,
|
system_role: String,
|
||||||
) -> Result<LLMHandle> {
|
) -> Result<LLMHandle> {
|
||||||
@@ -51,7 +40,6 @@ impl LLMHandle {
|
|||||||
Ok(LLMHandle {
|
Ok(LLMHandle {
|
||||||
client,
|
client,
|
||||||
chat_request,
|
chat_request,
|
||||||
cmd_root,
|
|
||||||
model: model.into(),
|
model: model.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -70,11 +58,6 @@ impl LLMHandle {
|
|||||||
while let Some(Ok(stream_event)) = stream.next().await {
|
while let Some(Ok(stream_event)) = stream.next().await {
|
||||||
if let ChatStreamEvent::Chunk(StreamChunk { content }) = stream_event {
|
if let ChatStreamEvent::Chunk(StreamChunk { content }) = stream_event {
|
||||||
text.push_str(&content);
|
text.push_str(&content);
|
||||||
} else if let ChatStreamEvent::End(end) = stream_event {
|
|
||||||
let texts = end.captured_texts().unwrap();
|
|
||||||
for text in texts.into_iter() {
|
|
||||||
info!("An answer: {}", text);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
46
src/setup.rs
46
src/setup.rs
@@ -1,78 +1,72 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use color_eyre::{
|
use color_eyre::{Result, eyre::WrapErr};
|
||||||
Result,
|
|
||||||
eyre::WrapErr,
|
|
||||||
};
|
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tracing::{
|
use tracing::{info, instrument};
|
||||||
info,
|
|
||||||
instrument,
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: use [clap(long, short, help_heading = Some(section))]
|
// TODO: use [clap(long, short, help_heading = Some(section))]
|
||||||
#[derive(Clone, Debug, Parser)]
|
#[derive(Clone, Debug, Parser)]
|
||||||
#[command(about, version)]
|
#[command(about, version)]
|
||||||
pub(crate) struct Args {
|
pub struct Args {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
/// API Key for the LLM in use.
|
/// API Key for the LLM in use.
|
||||||
pub(crate) api_key: Option<String>,
|
pub api_key: Option<String>,
|
||||||
|
|
||||||
#[arg(short, long, default_value = "https://api.openai.com")]
|
#[arg(short, long, default_value = "https://api.openai.com")]
|
||||||
/// Base URL for the LLM API to use.
|
/// Base URL for the LLM API to use.
|
||||||
pub(crate) base_url: Option<String>,
|
pub base_url: Option<String>,
|
||||||
|
|
||||||
/// Directory to use for chroot (recommended).
|
/// Directory to use for chroot (recommended).
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub(crate) chroot_dir: Option<String>,
|
pub chroot_dir: Option<String>,
|
||||||
|
|
||||||
/// Root directory for file based command structure.
|
/// Root directory for file based command structure.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub(crate) command_dir: Option<String>,
|
pub command_dir: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
/// Instructions to the model on how to behave.
|
/// Instructions to the model on how to behave.
|
||||||
pub(crate) intruct: Option<String>,
|
pub instruct: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub(crate) model: Option<String>,
|
pub model: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
/// List of IRC channels to join.
|
/// List of IRC channels to join.
|
||||||
pub(crate) channels: Option<Vec<String>>,
|
pub channels: Option<Vec<String>>,
|
||||||
|
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
/// Custom configuration file location if need be.
|
/// Custom configuration file location if need be.
|
||||||
pub(crate) config_file: Option<PathBuf>,
|
pub config_file: Option<PathBuf>,
|
||||||
|
|
||||||
#[arg(short, long, default_value = "irc.libera.chat")]
|
#[arg(short, long, default_value = "irc.libera.chat")]
|
||||||
/// IRC server.
|
/// IRC server.
|
||||||
pub(crate) server: Option<String>,
|
pub server: Option<String>,
|
||||||
|
|
||||||
#[arg(short, long, default_value = "6697")]
|
#[arg(short, long, default_value = "6697")]
|
||||||
/// Port of the IRC server.
|
/// Port of the IRC server.
|
||||||
pub(crate) port: Option<String>,
|
pub port: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
/// IRC Nickname.
|
/// IRC Nickname.
|
||||||
pub(crate) nickname: Option<String>,
|
pub nickname: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
/// IRC Nick Password
|
/// IRC Nick Password
|
||||||
pub(crate) nick_password: Option<String>,
|
pub nick_password: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
/// IRC Username
|
/// IRC Username
|
||||||
pub(crate) username: Option<String>,
|
pub username: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
/// Whether or not to use TLS when connecting to the IRC server.
|
/// Whether or not to use TLS when connecting to the IRC server.
|
||||||
pub(crate) use_tls: Option<bool>,
|
pub use_tls: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct Setup {
|
pub struct Setup {
|
||||||
pub(crate) config: Config,
|
pub config: Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
@@ -104,7 +98,7 @@ pub async fn init() -> Result<Setup> {
|
|||||||
.set_override_option("chroot-dir", args.chroot_dir.clone())?
|
.set_override_option("chroot-dir", args.chroot_dir.clone())?
|
||||||
.set_override_option("command-path", args.command_dir.clone())?
|
.set_override_option("command-path", args.command_dir.clone())?
|
||||||
.set_override_option("model", args.model.clone())?
|
.set_override_option("model", args.model.clone())?
|
||||||
.set_override_option("instruct", args.model.clone())?
|
.set_override_option("instruct", args.instruct.clone())?
|
||||||
.set_override_option("channels", args.channels.clone())?
|
.set_override_option("channels", args.channels.clone())?
|
||||||
.set_override_option("server", args.server.clone())?
|
.set_override_option("server", args.server.clone())?
|
||||||
.set_override_option("port", args.port.clone())? // FIXME: Make this a default here not in clap.
|
.set_override_option("port", args.port.clone())? // FIXME: Make this a default here not in clap.
|
||||||
|
|||||||
492
tests/event_test.rs
Normal file
492
tests/event_test.rs
Normal file
@@ -0,0 +1,492 @@
|
|||||||
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
use robotnik::{event::Event, event_manager::EventManager};
|
||||||
|
use rstest::rstest;
|
||||||
|
use tokio::{
|
||||||
|
io::{AsyncBufReadExt, BufReader},
|
||||||
|
net::UnixStream,
|
||||||
|
time::timeout,
|
||||||
|
};
|
||||||
|
|
||||||
|
const TEST_SOCKET_BASE: &str = "/tmp/robotnik_test";
|
||||||
|
|
||||||
|
/// Helper to create unique socket paths for parallel tests
|
||||||
|
fn test_socket_path(name: &str) -> String {
|
||||||
|
format!("{}_{}_{}", TEST_SOCKET_BASE, name, std::process::id())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper to read one JSON event from a stream
|
||||||
|
async fn read_event(
|
||||||
|
reader: &mut BufReader<UnixStream>,
|
||||||
|
) -> Result<Event, Box<dyn std::error::Error>> {
|
||||||
|
let mut line = String::new();
|
||||||
|
reader.read_line(&mut line).await?;
|
||||||
|
let event: Event = serde_json::from_str(&line)?;
|
||||||
|
Ok(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper to read all available events with a timeout
|
||||||
|
async fn read_events_with_timeout(
|
||||||
|
reader: &mut BufReader<UnixStream>,
|
||||||
|
max_count: usize,
|
||||||
|
timeout_ms: u64,
|
||||||
|
) -> Vec<String> {
|
||||||
|
let mut events = Vec::new();
|
||||||
|
for _ in 0..max_count {
|
||||||
|
let mut line = String::new();
|
||||||
|
match timeout(
|
||||||
|
Duration::from_millis(timeout_ms),
|
||||||
|
reader.read_line(&mut line),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(Ok(0)) => break, // EOF
|
||||||
|
Ok(Ok(_)) => events.push(line),
|
||||||
|
Ok(Err(_)) => break, // Read error
|
||||||
|
Err(_) => break, // Timeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
events
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_client_connects_and_receives_event() {
|
||||||
|
let socket_path = test_socket_path("basic_connect");
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Give the listener time to start
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// Broadcast an event
|
||||||
|
let event = Event::new("test message");
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
|
||||||
|
// Connect as a client
|
||||||
|
let stream = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader = BufReader::new(stream);
|
||||||
|
|
||||||
|
// Read the event
|
||||||
|
let mut line = String::new();
|
||||||
|
reader.read_line(&mut line).await.unwrap();
|
||||||
|
|
||||||
|
assert!(line.contains("test message"));
|
||||||
|
assert!(line.ends_with('\n'));
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_client_receives_event_history() {
|
||||||
|
let socket_path = test_socket_path("event_history");
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Broadcast events BEFORE starting the listener
|
||||||
|
for i in 0..5 {
|
||||||
|
let event = Event::new(format!("historical event {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// Connect as a client
|
||||||
|
let stream = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader = BufReader::new(stream);
|
||||||
|
|
||||||
|
// Should receive all 5 historical events
|
||||||
|
let events = read_events_with_timeout(&mut reader, 5, 100).await;
|
||||||
|
|
||||||
|
assert_eq!(events.len(), 5);
|
||||||
|
assert!(events[0].contains("historical event 0"));
|
||||||
|
assert!(events[4].contains("historical event 4"));
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_multiple_clients_receive_same_events() {
|
||||||
|
let socket_path = test_socket_path("multiple_clients");
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// Connect 3 clients
|
||||||
|
let stream1 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let stream2 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let stream3 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
|
||||||
|
let mut reader1 = BufReader::new(stream1);
|
||||||
|
let mut reader2 = BufReader::new(stream2);
|
||||||
|
let mut reader3 = BufReader::new(stream3);
|
||||||
|
|
||||||
|
// Broadcast a new event
|
||||||
|
let event = Event::new("broadcast to all");
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
|
||||||
|
// All clients should receive the event
|
||||||
|
let mut line1 = String::new();
|
||||||
|
let mut line2 = String::new();
|
||||||
|
let mut line3 = String::new();
|
||||||
|
|
||||||
|
timeout(Duration::from_millis(100), reader1.read_line(&mut line1))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
timeout(Duration::from_millis(100), reader2.read_line(&mut line2))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
timeout(Duration::from_millis(100), reader3.read_line(&mut line3))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert!(line1.contains("broadcast to all"));
|
||||||
|
assert!(line2.contains("broadcast to all"));
|
||||||
|
assert!(line3.contains("broadcast to all"));
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_late_joiner_receives_full_history() {
|
||||||
|
let socket_path = test_socket_path("late_joiner");
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// First client connects
|
||||||
|
let stream1 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader1 = BufReader::new(stream1);
|
||||||
|
|
||||||
|
// Broadcast several events
|
||||||
|
for i in 0..10 {
|
||||||
|
let event = Event::new(format!("event {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Consume events from first client
|
||||||
|
let _ = read_events_with_timeout(&mut reader1, 10, 100).await;
|
||||||
|
|
||||||
|
// Late joiner connects
|
||||||
|
let stream2 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader2 = BufReader::new(stream2);
|
||||||
|
|
||||||
|
// Late joiner should receive all 10 events from history
|
||||||
|
let events = read_events_with_timeout(&mut reader2, 10, 100).await;
|
||||||
|
|
||||||
|
assert_eq!(events.len(), 10);
|
||||||
|
assert!(events[0].contains("event 0"));
|
||||||
|
assert!(events[9].contains("event 9"));
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_client_receives_events_in_order() {
|
||||||
|
let socket_path = test_socket_path("event_order");
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// Connect client
|
||||||
|
let stream = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader = BufReader::new(stream);
|
||||||
|
|
||||||
|
// Broadcast events rapidly
|
||||||
|
let count = 50;
|
||||||
|
for i in 0..count {
|
||||||
|
let event = Event::new(format!("sequence {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read all events
|
||||||
|
let events = read_events_with_timeout(&mut reader, count, 500).await;
|
||||||
|
|
||||||
|
assert_eq!(events.len(), count);
|
||||||
|
|
||||||
|
// Verify order
|
||||||
|
for (i, event) in events.iter().enumerate() {
|
||||||
|
assert!(
|
||||||
|
event.contains(&format!("sequence {}", i)),
|
||||||
|
"Event {} out of order: {}",
|
||||||
|
i,
|
||||||
|
event
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_concurrent_broadcasts_during_client_connections() {
|
||||||
|
let socket_path = test_socket_path("concurrent_ops");
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// Connect client 1 BEFORE any broadcasts
|
||||||
|
let stream1 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader1 = BufReader::new(stream1);
|
||||||
|
|
||||||
|
// Spawn a task that continuously broadcasts
|
||||||
|
let broadcast_manager = Arc::clone(&manager);
|
||||||
|
let broadcast_handle = tokio::spawn(async move {
|
||||||
|
for i in 0..100 {
|
||||||
|
let event = Event::new(format!("concurrent event {}", i));
|
||||||
|
broadcast_manager.broadcast(&event).await.unwrap();
|
||||||
|
tokio::time::sleep(Duration::from_millis(5)).await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// While broadcasting, connect more clients at different times
|
||||||
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
|
let stream2 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader2 = BufReader::new(stream2);
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(150)).await;
|
||||||
|
let stream3 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader3 = BufReader::new(stream3);
|
||||||
|
|
||||||
|
// Wait for broadcasts to complete
|
||||||
|
broadcast_handle.await.unwrap();
|
||||||
|
|
||||||
|
// All clients should have received events
|
||||||
|
let events1 = read_events_with_timeout(&mut reader1, 100, 200).await;
|
||||||
|
let events2 = read_events_with_timeout(&mut reader2, 100, 200).await;
|
||||||
|
let events3 = read_events_with_timeout(&mut reader3, 100, 200).await;
|
||||||
|
|
||||||
|
// Client 1 connected first (before any broadcasts), should get all 100
|
||||||
|
assert_eq!(events1.len(), 100);
|
||||||
|
|
||||||
|
// Client 2 connected after ~20 events were broadcast
|
||||||
|
// Gets ~20 from history + ~80 live = 100
|
||||||
|
assert_eq!(events2.len(), 100);
|
||||||
|
|
||||||
|
// Client 3 connected after ~50 events were broadcast
|
||||||
|
// Gets ~50 from history + ~50 live = 100
|
||||||
|
assert_eq!(events3.len(), 100);
|
||||||
|
|
||||||
|
// Verify they all received events in order
|
||||||
|
assert!(events1[0].contains("concurrent event 0"));
|
||||||
|
assert!(events2[0].contains("concurrent event 0"));
|
||||||
|
assert!(events3[0].contains("concurrent event 0"));
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_buffer_overflow_affects_new_clients() {
|
||||||
|
let socket_path = test_socket_path("buffer_overflow");
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Broadcast more than buffer max (1000)
|
||||||
|
for i in 0..1100 {
|
||||||
|
let event = Event::new(format!("overflow event {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// New client connects
|
||||||
|
let stream = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader = BufReader::new(stream);
|
||||||
|
|
||||||
|
// Should receive exactly 1000 events (buffer max)
|
||||||
|
let events = read_events_with_timeout(&mut reader, 1100, 500).await;
|
||||||
|
|
||||||
|
assert_eq!(events.len(), 1000);
|
||||||
|
|
||||||
|
// First event should be 100 (oldest 100 were evicted)
|
||||||
|
assert!(events[0].contains("overflow event 100"));
|
||||||
|
|
||||||
|
// Last event should be 1099
|
||||||
|
assert!(events[999].contains("overflow event 1099"));
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[case(10, 1)]
|
||||||
|
#[case(50, 5)]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_client_count_scaling(#[case] num_clients: usize, #[case] events_per_client: usize) {
|
||||||
|
let socket_path = test_socket_path(&format!("scaling_{}_{}", num_clients, events_per_client));
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// Connect many clients
|
||||||
|
let mut readers = Vec::new();
|
||||||
|
for _ in 0..num_clients {
|
||||||
|
let stream = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
readers.push(BufReader::new(stream));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Broadcast events
|
||||||
|
for i in 0..events_per_client {
|
||||||
|
let event = Event::new(format!("scale event {}", i));
|
||||||
|
manager.broadcast(&event).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify all clients received all events
|
||||||
|
for reader in &mut readers {
|
||||||
|
let events = read_events_with_timeout(reader, events_per_client, 200).await;
|
||||||
|
assert_eq!(events.len(), events_per_client);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_client_disconnect_doesnt_affect_others() {
|
||||||
|
let socket_path = test_socket_path("disconnect");
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// Connect 3 clients
|
||||||
|
let stream1 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let stream2 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let stream3 = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
|
||||||
|
let mut reader1 = BufReader::new(stream1);
|
||||||
|
let mut reader2 = BufReader::new(stream2);
|
||||||
|
let mut reader3 = BufReader::new(stream3);
|
||||||
|
|
||||||
|
// Broadcast initial event
|
||||||
|
manager
|
||||||
|
.broadcast(&Event::new("before disconnect"))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// All receive it
|
||||||
|
let _ = read_events_with_timeout(&mut reader1, 1, 100).await;
|
||||||
|
let _ = read_events_with_timeout(&mut reader2, 1, 100).await;
|
||||||
|
let _ = read_events_with_timeout(&mut reader3, 1, 100).await;
|
||||||
|
|
||||||
|
// Drop client 2 (simulates disconnect)
|
||||||
|
drop(reader2);
|
||||||
|
|
||||||
|
// Broadcast another event
|
||||||
|
manager
|
||||||
|
.broadcast(&Event::new("after disconnect"))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Clients 1 and 3 should still receive it
|
||||||
|
let events1 = read_events_with_timeout(&mut reader1, 1, 100).await;
|
||||||
|
let events3 = read_events_with_timeout(&mut reader3, 1, 100).await;
|
||||||
|
|
||||||
|
assert_eq!(events1.len(), 1);
|
||||||
|
assert_eq!(events3.len(), 1);
|
||||||
|
assert!(events1[0].contains("after disconnect"));
|
||||||
|
assert!(events3[0].contains("after disconnect"));
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_json_deserialization_of_received_events() {
|
||||||
|
let socket_path = test_socket_path("json_deser");
|
||||||
|
let manager = Arc::new(EventManager::new().unwrap());
|
||||||
|
|
||||||
|
// Start the listener
|
||||||
|
let listener_manager = Arc::clone(&manager);
|
||||||
|
let socket_path_clone = socket_path.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
listener_manager.start_listening(socket_path_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
// Broadcast an event with special characters
|
||||||
|
let test_message = "special chars: @#$% newline\\n tab\\t quotes \"test\"";
|
||||||
|
manager.broadcast(&Event::new(test_message)).await.unwrap();
|
||||||
|
|
||||||
|
// Connect and deserialize
|
||||||
|
let stream = UnixStream::connect(&socket_path).await.unwrap();
|
||||||
|
let mut reader = BufReader::new(stream);
|
||||||
|
|
||||||
|
let mut line = String::new();
|
||||||
|
reader.read_line(&mut line).await.unwrap();
|
||||||
|
|
||||||
|
// Should be valid JSON
|
||||||
|
let parsed: serde_json::Value = serde_json::from_str(&line.trim()).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(parsed["message"], test_message);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
let _ = std::fs::remove_file(&socket_path);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user