|
1 | 1 | (ns simulflow.processors.llm-context-aggregator-test |
2 | 2 | (:require |
3 | 3 | [clojure.core.async :as a] |
4 | | - [clojure.string :as str] |
5 | 4 | [clojure.test :refer [deftest is testing]] |
6 | 5 | [simulflow.frame :as frame] |
7 | 6 | [simulflow.mock-data :as mock] |
8 | | - [simulflow.processors.llm-context-aggregator :as sut] |
9 | | - [taoensso.telemere :as t])) |
| 7 | + [simulflow.processors.llm-context-aggregator :as sut])) |
10 | 8 |
|
11 | 9 | (deftest concat-context-test |
12 | 10 | (testing "concat-context" |
|
537 | 535 | ;; Use real assemble-sentence function, no mocking |
538 | 536 | (let [initial-state {::sut/accumulator "Hello"} |
539 | 537 | text-chunk (frame/llm-text-chunk " world.") |
540 | | - [new-state {:keys [out]}] (sut/llm-sentence-assembler-transform initial-state :in text-chunk)] |
| 538 | + [new-state {:keys [sys-out]}] (sut/llm-sentence-assembler-transform initial-state :in text-chunk)] |
541 | 539 |
|
542 | 540 | ;; Should complete sentence and reset accumulator |
543 | 541 | (is (= "" (::sut/accumulator new-state))) |
544 | | - (is (= 1 (count out))) |
545 | | - (is (frame/speak-frame? (first out))) |
546 | | - (is (= "Hello world." (:frame/data (first out)))))) |
| 542 | + (is (= 1 (count sys-out))) |
| 543 | + (is (frame/speak-frame? (first sys-out))) |
| 544 | + (is (= "Hello world." (:frame/data (first sys-out)))))) |
547 | 545 |
|
548 | 546 | (testing "accumulates partial sentences" |
549 | 547 | ;; Test with text that doesn't end a sentence |
|
574 | 572 | (testing "completes sentences with exclamation marks" |
575 | 573 | (let [initial-state {::sut/accumulator "Hello world"} |
576 | 574 | text-chunk (frame/llm-text-chunk "!") |
577 | | - [new-state {:keys [out]}] (sut/llm-sentence-assembler-transform initial-state :in text-chunk)] |
| 575 | + [new-state {:keys [sys-out]}] (sut/llm-sentence-assembler-transform initial-state :in text-chunk)] |
578 | 576 |
|
579 | 577 | (is (= "" (::sut/accumulator new-state))) |
580 | | - (is (= 1 (count out))) |
581 | | - (is (frame/speak-frame? (first out))) |
582 | | - (is (= "Hello world!" (:frame/data (first out)))))) |
| 578 | + (is (= 1 (count sys-out))) |
| 579 | + (is (frame/speak-frame? (first sys-out))) |
| 580 | + (is (= "Hello world!" (:frame/data (first sys-out)))))) |
583 | 581 |
|
584 | 582 | (testing "completes sentences with question marks" |
585 | 583 | (let [initial-state {::sut/accumulator "How are you"} |
586 | 584 | text-chunk (frame/llm-text-chunk "?") |
587 | | - [new-state {:keys [out]}] (sut/llm-sentence-assembler-transform initial-state :in text-chunk)] |
| 585 | + [new-state {:keys [sys-out]}] (sut/llm-sentence-assembler-transform initial-state :in text-chunk)] |
588 | 586 |
|
589 | 587 | (is (= "" (::sut/accumulator new-state))) |
590 | | - (is (= 1 (count out))) |
591 | | - (is (frame/speak-frame? (first out))) |
592 | | - (is (= "How are you?" (:frame/data (first out))))))) |
| 588 | + (is (= 1 (count sys-out))) |
| 589 | + (is (frame/speak-frame? (first sys-out))) |
| 590 | + (is (= "How are you?" (:frame/data (first sys-out))))))) |
593 | 591 |
|
594 | 592 | (testing "interruption handling" |
595 | 593 | (testing "control-interrupt-start clears accumulator and sets interrupted state" |
|
686 | 684 |
|
687 | 685 | ;; 4. After resuming, text chunks are processed again |
688 | 686 | (let [new-text-chunk (frame/llm-text-chunk "New sentence.") |
689 | | - [final-state {:keys [out]}] (sut/llm-sentence-assembler-transform |
690 | | - resumed-state :in new-text-chunk)] |
| 687 | + [final-state {:keys [sys-out]}] (sut/llm-sentence-assembler-transform |
| 688 | + resumed-state :in new-text-chunk)] |
691 | 689 | (is (= "" (::sut/accumulator final-state))) |
692 | 690 | (is (= false (:pipeline/interrupted? final-state))) |
693 | | - (is (= 1 (count out))) |
694 | | - (is (frame/speak-frame? (first out))) |
695 | | - (is (= "New sentence." (:frame/data (first out))))))))) |
| 691 | + (is (= 1 (count sys-out))) |
| 692 | + (is (frame/speak-frame? (first sys-out))) |
| 693 | + (is (= "New sentence." (:frame/data (first sys-out))))))))) |
696 | 694 |
|
697 | 695 | (testing "multiple interrupt commands are idempotent" |
698 | 696 | (let [initial-state {::sut/accumulator "some text"} |
|
785 | 783 | (let [initial-state {::sut/accumulator ""} |
786 | 784 |
|
787 | 785 | ;; Build up a sentence word by word |
788 | | - [state1 out1] (sut/llm-sentence-assembler-transform |
789 | | - initial-state :in (frame/llm-text-chunk "The U.S.A. is")) |
790 | | - [state2 out2] (sut/llm-sentence-assembler-transform |
791 | | - state1 :in (frame/llm-text-chunk " a great")) |
792 | | - [state3 {:keys [out]}] (sut/llm-sentence-assembler-transform |
793 | | - state2 :in (frame/llm-text-chunk " country!"))] |
| 786 | + [state1 sys-out1] (sut/llm-sentence-assembler-transform |
| 787 | + initial-state :in (frame/llm-text-chunk "The U.S.A. is")) |
| 788 | + [state2 sys-out2] (sut/llm-sentence-assembler-transform |
| 789 | + state1 :in (frame/llm-text-chunk " a great")) |
| 790 | + [state3 {:keys [sys-out]}] (sut/llm-sentence-assembler-transform |
| 791 | + state2 :in (frame/llm-text-chunk " country!"))] |
794 | 792 |
|
795 | 793 | ;; First two chunks should accumulate (no sentence end detected) |
796 | | - (is (nil? out1)) |
797 | | - (is (nil? out2)) |
| 794 | + (is (nil? sys-out1)) |
| 795 | + (is (nil? sys-out2)) |
798 | 796 |
|
799 | 797 | ;; Third chunk with exclamation should complete sentence |
800 | | - (is (= 1 (count out))) |
801 | | - (is (frame/speak-frame? (first out))) |
802 | | - (is (= "The U.S.A. is a great country!" (:frame/data (first out)))) |
| 798 | + (is (= 1 (count sys-out))) |
| 799 | + (is (frame/speak-frame? (first sys-out))) |
| 800 | + (is (= "The U.S.A. is a great country!" (:frame/data (first sys-out)))) |
803 | 801 | (is (= "" (::sut/accumulator state3))))) |
804 | 802 |
|
805 | 803 | (testing "handles multiple sentence types" |
806 | 804 | ;; Test period |
807 | | - (let [[_state {:keys [out]}] (sut/llm-sentence-assembler-transform |
808 | | - {::sut/accumulator "Hello"} :in (frame/llm-text-chunk " world."))] |
809 | | - (is (= 1 (count out))) |
810 | | - (is (= "Hello world." (:frame/data (first out))))) |
| 805 | + (let [[_state {:keys [sys-out]}] (sut/llm-sentence-assembler-transform |
| 806 | + {::sut/accumulator "Hello"} :in (frame/llm-text-chunk " world."))] |
| 807 | + (is (= 1 (count sys-out))) |
| 808 | + (is (= "Hello world." (:frame/data (first sys-out))))) |
811 | 809 |
|
812 | 810 | ;; Test question mark |
813 | | - (let [[_state {:keys [out]}] (sut/llm-sentence-assembler-transform |
814 | | - {::sut/accumulator "How are"} :in (frame/llm-text-chunk " you?"))] |
815 | | - (is (= 1 (count out))) |
816 | | - (is (= "How are you?" (:frame/data (first out))))) |
| 811 | + (let [[_state {:keys [sys-out]}] (sut/llm-sentence-assembler-transform |
| 812 | + {::sut/accumulator "How are"} :in (frame/llm-text-chunk " you?"))] |
| 813 | + (is (= 1 (count sys-out))) |
| 814 | + (is (= "How are you?" (:frame/data (first sys-out))))) |
817 | 815 |
|
818 | 816 | ;; Test exclamation |
819 | | - (let [[_state {:keys [out]}] (sut/llm-sentence-assembler-transform |
820 | | - {::sut/accumulator "Great"} :in (frame/llm-text-chunk " job!"))] |
821 | | - (is (= 1 (count out))) |
822 | | - (is (= "Great job!" (:frame/data (first out))))))))) |
| 817 | + (let [[_state {:keys [sys-out]}] (sut/llm-sentence-assembler-transform |
| 818 | + {::sut/accumulator "Great"} :in (frame/llm-text-chunk " job!"))] |
| 819 | + (is (= 1 (count sys-out))) |
| 820 | + (is (= "Great job!" (:frame/data (first sys-out))))))))) |
0 commit comments