REFAC: Standardize on Cognitive Cycle and harden harness

This commit is contained in:
2026-04-16 12:00:12 -04:00
parent 2d4a6d1586
commit 53eee06225
39 changed files with 236 additions and 2725 deletions

43
tests/act-tests.lisp Normal file
View File

@@ -0,0 +1,43 @@
(defpackage :opencortex-act-tests
(:use :cl :fiveam :opencortex))
(in-package :opencortex-act-tests)
(def-suite act-suite
:description "Verification of the Act Gate and Symbolic Guard.")
(in-suite act-suite)
(test test-act-gate-symbolic-guard-bypass
"Verify that opencortex:act-gate proceeds normally when no skill intercepts."
(clrhash opencortex::*skills-registry*)
(let* ((signal (list :type :EVENT :status nil :depth 0 :approved-action '(:target :cli :payload (:text "Hello"))))
(result (opencortex:act-gate signal)))
(is (eq :acted (getf signal :status)))
(is (null result))))
(test test-act-gate-symbolic-guard-interception
"Verify that opencortex:act-gate intercepts actions when a skill returns a LOG/EVENT."
(clrhash opencortex::*skills-registry*)
;; Register a mock skill that acts like a symbolic guard
(opencortex::defskill :mock-bouncer
:priority 200
:trigger (lambda (ctx) t)
:deterministic (lambda (action ctx)
(declare (ignore action ctx))
'(:type :LOG :payload (:text "BLOCKED BY SYMBOLIC GUARD"))))
(let* ((signal (list :type :EVENT :status nil :depth 0 :approved-action '(:target :shell :payload (:cmd "ls"))))
(result (opencortex:act-gate signal)))
(is (eq :acted (getf signal :status)))
(is (not (null result)))
(is (eq :LOG (getf result :type)))
(is (search "BLOCKED BY SYMBOLIC GUARD" (getf (getf result :payload) :text)))
;; The approved action in signal should be NIL'd out
(is (null (getf signal :approved-action)))))
(test test-act-gate-symbolic-guard-pass-through
"Verify that opencortex:act-gate allows actions when skills permit them."
(clrhash opencortex::*skills-registry*)
(let* ((signal (list :type :EVENT :status nil :depth 0 :approved-action '(:target :cli :payload (:text "Allowed"))))
(result (opencortex:act-gate signal)))
(is (eq :acted (getf signal :status)))
(is (equal '(:target :cli :payload (:text "Allowed")) (getf signal :approved-action)))))

View File

@@ -22,7 +22,9 @@
:priority 50
:trigger (lambda (ctx) t) ; always triggers
:probabilistic (lambda (ctx) "Mock probabilistic")
:deterministic (lambda (action ctx) nil))) ; rejects everything
:deterministic (lambda (action ctx)
(declare (ignore action ctx))
(list :type :LOG :payload (list :text "Action rejected by skill heuristics"))))) ; rejects everything
(test test-perceive-gate
"Perceive gate should update the object store and normalize signal."
@@ -37,9 +39,9 @@
(setup-mock-skills)
(let* ((candidate (list :type :REQUEST :payload (list :action :eval :code "(shell-command \"rm -rf /\")")))
(signal (list :type :EVENT :candidate candidate))
(result (decide-gate signal)))
(is (eq :decided (getf result :status)))
(let ((approved (getf result :approved-action)))
(result (deterministic-verify candidate signal)))
(let ((approved result))
(is (eq :LOG (getf approved :type)))
(is (search "Action rejected by skill heuristics" (getf (getf approved :payload) :text))))))
@@ -58,14 +60,14 @@
(test test-env-loading
"Verify that environment variables are accessible."
(setf (uiop:getenv "LLM_ENDPOINT") "http://mock")
(setf (uiop:getenv "MEMEX_USER") "Amr")
(sb-posix:putenv "LLM_ENDPOINT=http://mock")
(sb-posix:putenv "MEMEX_USER=Amr")
(is (not (null (uiop:getenv "LLM_ENDPOINT"))))
(is (stringp (opencortex::get-env "MEMEX_USER"))))
(is (stringp (uiop:getenv "MEMEX_USER"))))
(test test-path-resolution
"Verify that context-resolve-path expands environment variables."
(setf (uiop:getenv "MEMEX_USER") "Amr")
(sb-posix:putenv "MEMEX_USER=Amr")
(let ((path "$MEMEX_USER/test"))
(is (search "Amr/test" (context-resolve-path path)))))