v0.3.0 finish: TUI tests, embedding wiring, gateway :configured, focus commands, export cleanup
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 2s
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 2s
- TUI: Fix stale contract (remove handle-return/*incoming-msgs*), rewrite 10->13 tests (38 checks, 100% pass). Export missing symbols from TUI package. Fix view-chat contract arity. - Gateway messaging: Add :configured key to registry (boolean, nil default). Fix contract to match (vault-based, not env-var-based). - Async Embedding Gateway: Add *embedding-backend* var, embeddings-compute function. Modify ingest-ast to populate vectors on new objects. Add EMBEDDING_PROVIDER env var support. Add Contract + 4 tests (8 checks). - Context Manager: Add /focus, /scope, /unfocus commands to TUI on-key handler. Commands degrade gracefully when context-manager not loaded. - Export hygiene: Remove 30+ ghost exports (undefined symbols). Remove duplicate/mismatched names. Exports now match actual definitions.
This commit is contained in:
@@ -11,21 +11,51 @@
|
||||
(push text (st :input-history))
|
||||
(setf (st :input-hpos) 0)
|
||||
(setf (st :scroll-offset) 0)
|
||||
(cond
|
||||
;; /eval command
|
||||
((and (>= (length text) 6)
|
||||
(string-equal (subseq text 0 6) "/eval "))
|
||||
(handler-case
|
||||
(let* ((*read-eval* t)
|
||||
(*package* (find-package :passepartout.gateway-tui))
|
||||
(r (eval (read-from-string (subseq text 6)))))
|
||||
(add-msg :system (format nil "=> ~s" r)))
|
||||
(error (c) (add-msg :system (format nil "=> ✗ ~a" c)))))
|
||||
;; Normal message
|
||||
(t
|
||||
(add-msg :user text)
|
||||
(send-daemon (list :type :event
|
||||
:payload (list :sensor :user-input :text text)))))
|
||||
(cond
|
||||
;; /eval command
|
||||
((and (>= (length text) 6)
|
||||
(string-equal (subseq text 0 6) "/eval "))
|
||||
(handler-case
|
||||
(let* ((*read-eval* t)
|
||||
(*package* (find-package :passepartout.gateway-tui))
|
||||
(r (eval (read-from-string (subseq text 6)))))
|
||||
(add-msg :system (format nil "=> ~s" r)))
|
||||
(error (c) (add-msg :system (format nil "=> ✗ ~a" c)))))
|
||||
;; /focus <project> — set project context
|
||||
((and (>= (length text) 7)
|
||||
(string-equal (subseq text 0 7) "/focus "))
|
||||
(let ((project (string-trim '(#\Space) (subseq text 7))))
|
||||
(if (and (fboundp 'focus-project) (> (length project) 0))
|
||||
(progn (funcall 'focus-project project nil)
|
||||
(add-msg :system (format nil "Focused on project: ~a" project)))
|
||||
(add-msg :system "Usage: /focus <project-name>"))))
|
||||
;; /scope <scope> — change context scope
|
||||
((and (>= (length text) 7)
|
||||
(string-equal (subseq text 0 7) "/scope "))
|
||||
(let ((scope-str (string-trim '(#\Space) (subseq text 7))))
|
||||
(cond
|
||||
((and (fboundp 'focus-session) (string-equal scope-str "session"))
|
||||
(funcall 'focus-session)
|
||||
(add-msg :system "Scope: session"))
|
||||
((and (fboundp 'focus-project) (string-equal scope-str "project"))
|
||||
(funcall 'focus-project nil nil)
|
||||
(add-msg :system "Scope: project"))
|
||||
((and (fboundp 'focus-memex) (string-equal scope-str "memex"))
|
||||
(funcall 'focus-memex)
|
||||
(add-msg :system "Scope: memex"))
|
||||
(t (add-msg :system "Usage: /scope memex|session|project")))))
|
||||
;; /unfocus — pop context
|
||||
((and (>= (length text) 8)
|
||||
(string-equal (subseq text 0 8) "/unfocus"))
|
||||
(if (fboundp 'unfocus)
|
||||
(progn (funcall 'unfocus)
|
||||
(add-msg :system "Popped context"))
|
||||
(add-msg :system "Context manager not loaded")))
|
||||
;; Normal message
|
||||
(t
|
||||
(add-msg :user text)
|
||||
(send-daemon (list :type :event
|
||||
:payload (list :sensor :user-input :text text)))))
|
||||
(setf (st :input-buffer) nil)
|
||||
(setf (st :dirty) (list t t t)))))
|
||||
;; Backspace
|
||||
@@ -168,19 +198,148 @@
|
||||
(ql:quickload :fiveam :silent t))
|
||||
|
||||
(defpackage :passepartout-tui-tests
|
||||
(:use :cl :passepartout)
|
||||
(:use :cl :passepartout :passepartout.gateway-tui)
|
||||
(:export #:tui-suite))
|
||||
|
||||
(in-package :passepartout-tui-tests)
|
||||
|
||||
(fiveam:def-suite tui-suite :description "Verification of the TUI parsing and styling logic")
|
||||
(fiveam:def-suite tui-suite :description "Verification of the TUI model and event handling")
|
||||
(fiveam:in-suite tui-suite)
|
||||
|
||||
(fiveam:test test-tui-connection-drop
|
||||
"Tier 2 Chaos: Verify that handle-return degrades gracefully when the daemon connection is lost."
|
||||
(let ((passepartout.gateway-tui::*incoming-msgs* nil)
|
||||
(passepartout.gateway-tui::*input-buffer* (make-array 5 :element-type 'character :initial-contents "hello" :fill-pointer 5 :adjustable t))
|
||||
(mock-stream (make-string-output-stream)))
|
||||
(close mock-stream)
|
||||
(passepartout.gateway-tui::handle-return mock-stream)
|
||||
(fiveam:is (member "ERROR: Connection to daemon lost." passepartout.gateway-tui::*incoming-msgs* :test #'string=))))
|
||||
(fiveam:test test-init-state
|
||||
"Contract model.1: init-state returns fresh state plist with required keys."
|
||||
(init-state)
|
||||
(fiveam:is (eq t (st :running)))
|
||||
(fiveam:is (eq :chat (st :mode)))
|
||||
(fiveam:is (eq nil (st :connected)))
|
||||
(fiveam:is (eq nil (st :stream)))
|
||||
(fiveam:is (eq nil (st :messages)))
|
||||
(fiveam:is (eq 0 (st :scroll-offset))))
|
||||
|
||||
(fiveam:test test-add-msg
|
||||
"Contract model.2: add-msg appends a message with role, content, and time."
|
||||
(init-state)
|
||||
(add-msg :user "hello")
|
||||
(let* ((msgs (st :messages))
|
||||
(msg (first msgs)))
|
||||
(fiveam:is (eq :user (getf msg :role)))
|
||||
(fiveam:is (string= "hello" (getf msg :content)))
|
||||
(fiveam:is (stringp (getf msg :time)))
|
||||
(fiveam:is (= 5 (length (getf msg :time))))))
|
||||
|
||||
(fiveam:test test-add-msg-dirty-flag
|
||||
"Contract model.2: add-msg sets dirty flags for status and chat."
|
||||
(init-state)
|
||||
(setf (st :dirty) (list nil nil nil))
|
||||
(add-msg :system "boot")
|
||||
(let ((dirty (st :dirty)))
|
||||
(fiveam:is (eq t (first dirty)))
|
||||
(fiveam:is (eq t (second dirty)))
|
||||
(fiveam:is (eq nil (third dirty)))))
|
||||
|
||||
(fiveam:test test-queue-event-roundtrip
|
||||
"Contract model.3: queue-event + drain-queue preserves events in order."
|
||||
(init-state)
|
||||
(queue-event '(:type :key :payload (:ch 13)))
|
||||
(queue-event '(:type :daemon :payload (:text "hi")))
|
||||
(let ((evs (drain-queue)))
|
||||
(fiveam:is (= 2 (length evs)))
|
||||
(fiveam:is (equal '(:type :key :payload (:ch 13)) (first evs)))
|
||||
(fiveam:is (equal '(:type :daemon :payload (:text "hi")) (second evs)))
|
||||
(fiveam:is (null (drain-queue)))))
|
||||
|
||||
(fiveam:test test-on-key-enter-sends-user-message
|
||||
"Contract 1: on-key with Enter extracts input, adds user message, clears buffer."
|
||||
(init-state)
|
||||
;; Simulate typing "test"
|
||||
(dolist (ch '(#\t #\e #\s #\t))
|
||||
(on-key (char-code ch)))
|
||||
(fiveam:is (string= "test" (input-string)))
|
||||
;; Simulate Enter key (char code 13)
|
||||
(on-key 13)
|
||||
;; Input buffer should be cleared
|
||||
(fiveam:is (string= "" (input-string)))
|
||||
;; A user message should be in the message list
|
||||
(let ((msgs (st :messages)))
|
||||
(fiveam:is (>= (length msgs) 1))
|
||||
(let ((last (first msgs)))
|
||||
(fiveam:is (eq :user (getf last :role)))
|
||||
(fiveam:is (string= "test" (getf last :content))))))
|
||||
|
||||
(fiveam:test test-on-key-eval-command
|
||||
"Contract 1: on-key handles /eval command and displays result."
|
||||
(init-state)
|
||||
;; Type "/eval (+ 1 2)"
|
||||
(dolist (ch (coerce "/eval (+ 1 2)" 'list))
|
||||
(on-key (char-code ch)))
|
||||
(on-key 13)
|
||||
(let ((msgs (st :messages)))
|
||||
(fiveam:is (>= (length msgs) 1))
|
||||
(let ((last-msg (first msgs)))
|
||||
(fiveam:is (eq :system (getf last-msg :role)))
|
||||
(fiveam:is (search "=> 3" (getf last-msg :content))))))
|
||||
|
||||
(fiveam:test test-on-key-backspace
|
||||
"Contract 1: on-key with Backspace removes last character from buffer."
|
||||
(init-state)
|
||||
(dolist (ch '(#\a #\b #\c))
|
||||
(on-key (char-code ch)))
|
||||
(fiveam:is (string= "abc" (input-string)))
|
||||
(on-key 127) ; Backspace
|
||||
(fiveam:is (string= "ab" (input-string))))
|
||||
|
||||
(fiveam:test test-disconnect-daemon
|
||||
"Contract 4: disconnect-daemon sets connected to nil and adds disconnect message."
|
||||
(init-state)
|
||||
(setf (st :connected) t
|
||||
(st :stream) (make-string-output-stream))
|
||||
(disconnect-daemon)
|
||||
(fiveam:is (eq nil (st :connected)))
|
||||
(fiveam:is (eq nil (st :stream)))
|
||||
(let ((msgs (st :messages)))
|
||||
(fiveam:is (>= (length msgs) 1))
|
||||
(fiveam:is (search "Disconnected" (getf (first msgs) :content)))))
|
||||
|
||||
(fiveam:test test-on-daemon-msg-handshake
|
||||
"Contract 2: on-daemon-msg handles handshake action."
|
||||
(init-state)
|
||||
(on-daemon-msg '(:type :event :payload (:action :handshake :version "9.9")))
|
||||
(let ((msg (first (st :messages))))
|
||||
(fiveam:is (eq :system (getf msg :role)))
|
||||
(fiveam:is (search "Connected v9.9" (getf msg :content)))))
|
||||
|
||||
(fiveam:test test-on-daemon-msg-text
|
||||
"Contract 2: on-daemon-msg routes text payload to agent message."
|
||||
(init-state)
|
||||
(on-daemon-msg '(:type :event :payload (:text "hello world")))
|
||||
(let ((msg (first (st :messages))))
|
||||
(fiveam:is (eq :agent (getf msg :role)))
|
||||
(fiveam:is (string= "hello world" (getf msg :content)))))
|
||||
|
||||
(fiveam:test test-on-key-focus-command
|
||||
"Contract 1: /focus command parses project name."
|
||||
(init-state)
|
||||
(dolist (ch (coerce "/focus myapp" 'list))
|
||||
(on-key (char-code ch)))
|
||||
(on-key 13)
|
||||
(let ((msg (first (st :messages))))
|
||||
;; When context-manager is loaded, shows "Focused"; otherwise shows "Usage"
|
||||
(fiveam:is (eq :system (getf msg :role)))))
|
||||
|
||||
(fiveam:test test-on-key-scope-command
|
||||
"Contract 1: /scope command with valid argument."
|
||||
(init-state)
|
||||
(dolist (ch (coerce "/scope memex" 'list))
|
||||
(on-key (char-code ch)))
|
||||
(on-key 13)
|
||||
(let ((msg (first (st :messages))))
|
||||
(fiveam:is (eq :system (getf msg :role)))))
|
||||
|
||||
(fiveam:test test-on-key-unfocus-command
|
||||
"Contract 1: /unfocus command dispatches correctly."
|
||||
(init-state)
|
||||
(dolist (ch (coerce "/unfocus" 'list))
|
||||
(on-key (char-code ch)))
|
||||
(on-key 13)
|
||||
(let ((msg (first (st :messages))))
|
||||
(fiveam:is (eq :system (getf msg :role)))))
|
||||
|
||||
Reference in New Issue
Block a user