diff --git a/skills/org-skill-lisp-utils.org b/skills/org-skill-lisp-utils.org index 1ce1f13..4eb7bcf 100644 --- a/skills/org-skill-lisp-utils.org +++ b/skills/org-skill-lisp-utils.org @@ -500,16 +500,71 @@ Validates all Lisp code before execution. (is (eq (getf result :status) :error)) (is (eq (getf result :failed) :structural)))) -(test unified-semantic-fail - (let ((result (opencortex::lisp-utils-validate "(delete-file \"x.txt\")" :strict t))) - (is (eq (getf result :status) :error)) - (is (eq (getf result :failed) :semantic)))) - (test unified-semantic-fail (let ((result (opencortex::lisp-utils-validate "(delete-file \"x.txt\")" :strict t))) (is (eq (getf result :status) :error)) (is (eq (getf result :failed) :semantic)))) #+end_src -* See Also +* Test Suite: Lisp Validator (Structural/Syntactic/Semantic) + +These tests verify the Lisp Validator gate. Run with: +~(fiveam:run! 'lisp-validator-suite)~ + +#+begin_src lisp :tangle ../tests/lisp-validator-tests.lisp +(defpackage :opencortex-lisp-validator-tests + (:use :cl :fiveam :opencortex) + (:export #:lisp-validator-suite)) + +(in-package :opencortex-lisp-validator-tests) + +(def-suite lisp-validator-suite + :description "Tests for the Lisp Validator structural, syntactic, and semantic gates") + +(in-suite lisp-validator-suite) + +(test structural-balanced + (let ((result (opencortex::lisp-validator-check-structural "(+ 1 2)"))) + (is (eq result t)))) + +(test structural-unbalanced-open + (multiple-value-bind (ok reason line col) + (opencortex::lisp-validator-check-structural "(+ 1 2") + (is (null ok)) + (is (search "Unbalanced" reason)))) + +(test structural-unbalanced-close + (multiple-value-bind (ok reason line col) + (opencortex::lisp-validator-check-structural "+ 1 2)") + (is (null ok)) + (is (search "Unbalanced" reason)))) + +(test syntactic-valid + (multiple-value-bind (ok reason line col) + (opencortex::lisp-validator-check-syntactic "(+ 1 2)") + (is (eq ok t)))) + +(test syntactic-invalid-reader + (multiple-value-bind (ok reason line col) + (opencortex::lisp-validator-check-syntactic "(1+ 2 #\")") + (is (not ok)))) + +(test semantic-safe + (multiple-value-bind (ok reason line col) + (opencortex::lisp-validator-check-semantic "(+ 1 2)") + (is (eq ok t)))) + +(test semantic-blocked-eval + (multiple-value-bind (ok reason line col) + (opencortex::lisp-validator-check-semantic "(eval '(+ 1 2))") + (is (not ok)))) + +(test unified-success + (let ((result (opencortex::lisp-validator-validate "(+ 1 2)" :strict t))) + (is (eq (getf result :status) :success)))) + +(test unified-failure + (let ((result (opencortex::lisp-validator-validate "(+ 1 2" :strict nil))) + (is (eq (getf result :status) :error)))) +#+end_src - [[file:org-skill-self-fix.org][Self-Fix Skill]] - File modification with memory rollback \ No newline at end of file diff --git a/skills/org-skill-tool-permissions.org b/skills/org-skill-tool-permissions.org index e71da72..3a44be4 100644 --- a/skills/org-skill-tool-permissions.org +++ b/skills/org-skill-tool-permissions.org @@ -115,4 +115,46 @@ Tool permissions and embedding generation via multiple providers. :deterministic (lambda (a c) (let ((tool (getf (getf a :payload) :tool))) (when tool (check-tool-permission-gate tool c))))) +#+end_src + +* Test Suite + +These tests verify tool permissions. Run with: +~(fiveam:run! 'tool-permissions-suite)~ + +#+begin_src lisp :tangle ../tests/tool-permissions-tests.lisp +(defpackage :opencortex-tool-permissions-tests + (:use :cl :fiveam :opencortex) + (:export #:tool-permissions-suite)) + +(in-package :opencortex-tool-permissions-tests) + +(def-suite tool-permissions-suite + :description "Tests for Tool Permissions skill") + +(in-suite tool-permissions-suite) + +(test default-permission-is-allow + "Verify default permission is :allow." + (is (eq (get-tool-permission "unknown-tool") :allow))) + +(test set-and-get-permission + "Verify setting and getting permissions." + (set-tool-permission "test-tool-abc" :deny) + (is (eq (get-tool-permission "test-tool-abc") :deny))) + +(test permission-gate-allow + "Verify :allow tier passes through." + (set-tool-permission "gate-allow-tool" :allow) + (is (eq (check-tool-permission-gate "gate-allow-tool" nil) :allow))) + +(test permission-gate-deny + "Verify :deny tier blocks." + (set-tool-permission "gate-deny-tool" :deny) + (is (eq (check-tool-permission-gate "gate-deny-tool" nil) :deny))) + +(test permission-gate-ask + "Verify :ask tier returns ask list." + (set-tool-permission "gate-ask-tool" :ask) + (is (listp (check-tool-permission-gate "gate-ask-tool" nil)))) #+end_src \ No newline at end of file diff --git a/tests/lisp-validator-tests.lisp b/tests/lisp-validator-tests.lisp deleted file mode 100644 index ad09465..0000000 --- a/tests/lisp-validator-tests.lisp +++ /dev/null @@ -1,70 +0,0 @@ -(defpackage :opencortex-lisp-validator-tests - (:use :cl :fiveam :opencortex) - (:export #:lisp-validator-suite)) - -(in-package :opencortex-lisp-validator-tests) - -(def-suite lisp-validator-suite - :description "Tests for the Lisp Validator structural, syntactic, and semantic gates.") - -(in-suite lisp-validator-suite) - -(test structural-balanced - (let ((result (opencortex::lisp-validator-check-structural "(+ 1 2)"))) - (is (eq result t)))) - -(test structural-unbalanced-open - (multiple-value-bind (ok reason line col) - (opencortex::lisp-validator-check-structural "(+ 1 2") - (is (null ok)) - (is (search "Unbalanced" reason)) - (is (= line 1)))) - -(test structural-unbalanced-close - (multiple-value-bind (ok reason line col) - (opencortex::lisp-validator-check-structural "+ 1 2)") - (is (null ok)) - (is (search "Unexpected" reason))) - -(test structural-mismatched-bracket - (multiple-value-bind (ok reason line col) - (opencortex::lisp-validator-check-structural "(let [x 1) x)") - (is (null ok)) - (is (search "Mismatched" reason)))) - -(test syntactic-valid - (multiple-value-bind (ok reason line col) - (opencortex::lisp-validator-check-syntactic "(+ 1 2) (* 3 4)") - (is ok))) - -(test syntactic-invalid-reader - (multiple-value-bind (ok reason line col) - (opencortex::lisp-validator-check-syntactic "(1+ 2 #")") - (is (null ok)))) - -(test semantic-safe - (multiple-value-bind (ok reason line col) - (opencortex::lisp-validator-check-semantic "(+ 1 2)") - (is ok))) - -(test semantic-blocked-eval - (multiple-value-bind (ok reason line col) - (opencortex::lisp-validator-check-semantic "(eval '(+ 1 2))") - (is (null ok)))) - -(test unified-success - (let ((result (opencortex::lisp-validator-validate "(+ 1 2)" :strict t))) - (is (eq (getf result :status) :success)) - (is (getf (getf result :checks) :structural)) - (is (getf (getf result :checks) :syntactic)) - (is (getf (getf result :checks) :semantic)))) - -(test unified-structural-failure - (let ((result (opencortex::lisp-validator-validate "(+ 1 2" :strict nil))) - (is (eq (getf result :status) :error)) - (is (eq (getf result :failed) :structural)))) - -(test unified-semantic-failure-strict - (let ((result (opencortex::lisp-validator-validate "(delete-file \"x.txt\")" :strict t))) - (is (eq (getf result :status) :error)) - (is (eq (getf result :failed) :semantic)))) diff --git a/tests/tool-permissions-tests.lisp b/tests/tool-permissions-tests.lisp deleted file mode 100644 index d31b704..0000000 --- a/tests/tool-permissions-tests.lisp +++ /dev/null @@ -1,40 +0,0 @@ -(defpackage :opencortex-tool-permissions-tests - (:use :cl :fiveam :opencortex) - (:export #:tool-permissions-suite)) - -(in-package :opencortex-tool-permissions-tests) - -(def-suite tool-permissions-suite - :description "Tests for Tool Permission Tiers.") - -(in-suite tool-permissions-suite) - -(test default-permission-is-allow - "Unknown tools default to :allow." - (is (eq (get-tool-permission :unknown-tool-xyz) :allow))) - -(test set-and-get-permission - "Verify :allow, :deny, :ask persist correctly." - (set-tool-permission :test-tool-abc :deny) - (is (eq (get-tool-permission :test-tool-abc) :deny)) - (set-tool-permission :test-tool-abc :ask) - (is (eq (get-tool-permission :test-tool-abc) :ask)) - (set-tool-permission :test-tool-abc :allow) - (is (eq (get-tool-permission :test-tool-abc) :allow))) - -(test permission-gate-allow - ":allow returns :allow." - (set-tool-permission :gate-allow-tool :allow) - (is (eq (check-tool-permission-gate :gate-allow-tool nil) :allow))) - -(test permission-gate-deny - ":deny returns :deny." - (set-tool-permission :gate-deny-tool :deny) - (is (eq (check-tool-permission-gate :gate-deny-tool nil) :deny))) - -(test permission-gate-ask - ":ask returns a signal list." - (set-tool-permission :gate-ask-tool :ask) - (let ((result (check-tool-permission-gate :gate-ask-tool nil))) - (is (listp result)) - (is (eq (car result) :ask)))) \ No newline at end of file