From f7209a8bb0ba6acd4f715d5fb10e1d54815977c2 Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Sat, 25 Apr 2026 19:38:28 -0400 Subject: [PATCH] WIP: Add enforcement tests to org-skill-engineering-standards - Added test block to Org file (Phase A: test-first) - Created tests/engineering-standards-tests.lisp - Tests exist but can't run - tangled lisp is out of sync LESSON: This demonstrates the LP workflow failure - the .lisp file wasn't regenerated when the .org was updated. The enforcement skill itself should catch this: tangled files must match Org source. This is exactly what org-skill-enforcement should block. --- skills/org-skill-engineering-standards.org | 70 ++++++++++++++++++++++ tests/engineering-standards-tests.lisp | 63 +++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 tests/engineering-standards-tests.lisp diff --git a/skills/org-skill-engineering-standards.org b/skills/org-skill-engineering-standards.org index bc2b9bd..e09fe33 100644 --- a/skills/org-skill-engineering-standards.org +++ b/skills/org-skill-engineering-standards.org @@ -163,6 +163,76 @@ The engineering standards skill is a HARD BLOCK gate. Violations are rejected, n :severity :warning)) #+end_src +** Test Suite + +These tests verify the enforcement logic. Run with: +~(fiveam:run! 'engineering-standards-suite)~ + +#+begin_src lisp :tangle ../tests/engineering-standards-tests.lisp +(defpackage :opencortex-engineering-standards-tests + (:use :cl :fiveam :opencortex) + (:export #:engineering-standards-suite)) + +(in-package :opencortex-engineering-standards-tests) + +(def-suite engineering-standards-suite + :description "Tests for Engineering Standards enforcement") + +(in-suite engineering-standards-suite) + +(test git-clean-check-clean + "verify-git-clean-p returns T when git tree is clean." + (let ((tmp-dir "/tmp/eng-std-test-clean/")) + (uiop:ensure-all-directories-exist (list tmp-dir)) + (uiop:run-program (list "git" "init" tmp-dir) :output nil) + (is (eq t (opencortex::verify-git-clean-p (uiop:ensure-directory-pathname tmp-dir)))) + (uiop:delete-directory-tree (uiop:ensure-directory-pathname tmp-dir) :validate t))) + +(test git-clean-check-dirty + "verify-git-clean-p returns NIL when git tree has uncommitted changes." + (let ((tmp-dir "/tmp/eng-std-test-dirty/")) + (uiop:ensure-all-directories-exist (list tmp-dir)) + (uiop:run-program (list "git" "init" tmp-dir) :output nil) + (with-open-file (f (merge-pathnames "test.txt" tmp-dir) :direction :output) + (write-line "test" f)) + (is (null (opencortex::verify-git-clean-p (uiop:ensure-directory-pathname tmp-dir)))) + (uiop:delete-directory-tree (uiop:ensure-directory-pathname tmp-dir) :validate t))) + +(test violation-struct + "engineering-violation struct is properly constructed." + (let ((v (opencortex::make-engineering-violation + :phase :pre-task + :rule :git-clean + :message "Test violation" + :severity :blocker))) + (is (eq :pre-task (opencortex::engineering-violation-phase v))) + (is (eq :git-clean (opencortex::engineering-violation-rule v))) + (is (string= "Test violation" (opencortex::engineering-violation-message v))) + (is (eq :blocker (opencortex::engineering-violation-severity v))))) + +(test gate-blocks-dirty-tree + "engineering-standards-gate blocks when git is dirty." + (let ((action (list :type :request + :payload (list :tool :write-file + :file "/tmp/test" + :content "test")))) + ;; Note: This test assumes git is clean in test environment + ;; The gate returns :log if dirty + (let ((result (opencortex::engineering-standards-gate action nil))) + (is (listp result)) + (when (eq (getf result :type) :log) + (is (search "dirty" (getf (getf result :payload) :text) :test #'char-equal)))))) + +(test gate-allows-clean-tree + "engineering-standards-gate passes when git is clean." + (let ((action (list :type :request + :payload (list :tool :read-file + :file "/tmp/test")))) + (let ((result (opencortex::engineering-standards-gate action nil))) + (is (listp result)) + (is (eq :request (getf result :type)))))) +#+end_src + ** Blocking Gate (Hard Enforcement) #+begin_src lisp :tangle ../library/gen/org-skill-engineering-standards.lisp diff --git a/tests/engineering-standards-tests.lisp b/tests/engineering-standards-tests.lisp new file mode 100644 index 0000000..3d43dd7 --- /dev/null +++ b/tests/engineering-standards-tests.lisp @@ -0,0 +1,63 @@ +(defpackage :opencortex-engineering-standards-tests + (:use :cl :fiveam :opencortex) + (:export #:engineering-standards-suite)) + +(in-package :opencortex-engineering-standards-tests) + +;; Load the skill functions first +(load "library/gen/org-skill-engineering-standards.lisp") + +(def-suite engineering-standards-suite + :description "Tests for Engineering Standards enforcement") + +(in-suite engineering-standards-suite) + +(test git-clean-check-clean + "verify-git-clean-p returns T when git tree is clean." + (let ((tmp-dir "/tmp/eng-std-test-clean/")) + (uiop:ensure-all-directories-exist (list tmp-dir)) + (uiop:run-program (list "git" "init" tmp-dir) :output nil) + (is (eq t (opencortex::verify-git-clean-p (uiop:ensure-directory-pathname tmp-dir)))) + (uiop:delete-directory-tree (uiop:ensure-directory-pathname tmp-dir) :validate t))) + +(test git-clean-check-dirty + "verify-git-clean-p returns NIL when git tree has uncommitted changes." + (let ((tmp-dir "/tmp/eng-std-test-dirty/")) + (uiop:ensure-all-directories-exist (list tmp-dir)) + (uiop:run-program (list "git" "init" tmp-dir) :output nil) + (with-open-file (f (merge-pathnames "test.txt" tmp-dir) :direction :output) + (write-line "test" f)) + (is (null (opencortex::verify-git-clean-p (uiop:ensure-directory-pathname tmp-dir)))) + (uiop:delete-directory-tree (uiop:ensure-directory-pathname tmp-dir) :validate t))) + +(test violation-struct + "engineering-violation struct is properly constructed." + (let ((v (opencortex::make-engineering-violation + :phase :pre-task + :rule :git-clean + :message "Test violation" + :severity :blocker))) + (is (eq :pre-task (opencortex::engineering-violation-phase v))) + (is (eq :git-clean (opencortex::engineering-violation-rule v))) + (is (string= "Test violation" (opencortex::engineering-violation-message v))) + (is (eq :blocker (opencortex::engineering-violation-severity v))))) + +(test gate-blocks-dirty-tree + "engineering-standards-gate blocks when git is dirty." + (let ((action (list :type :request + :payload (list :tool :write-file + :file "/tmp/test" + :content "test")))) + (let ((result (opencortex::engineering-standards-gate action nil))) + (is (listp result)) + (when (eq (getf result :type) :log) + (is (search "dirty" (getf (getf result :payload) :text) :test #'char-equal)))))) + +(test gate-allows-clean-tree + "engineering-standards-gate passes when git is clean." + (let ((action (list :type :request + :payload (list :tool :read-file + :file "/tmp/test")))) + (let ((result (opencortex::engineering-standards-gate action nil))) + (is (listp result)) + (is (eq :request (getf result :type)))))) \ No newline at end of file