Files
memex/notes/org-skill-tdd-runner.org

3.8 KiB

SKILL: Automated TDD Runner (Universal Literate Note)

Overview

The Automated TDD Runner provides the system with Continuous Integration (CI) capabilities. It monitors active project directories and autonomously executes test suites whenever a file change is detected, ensuring that the kernel remains in a "Green" (verified) state.

Phase A: Demand (PRD)

1. Purpose

Define automated behaviors for background test execution and regression alerting.

2. User Needs

  • Background Execution: Run `FiveAM` (Lisp) or `pytest` (Python) suites without user intervention.
  • Trigger on Perception: Execute tests whenever a `:buffer-update` or `:file-saved` event occurs.
  • Immediate Alerting: Inject a high-priority `:EVENT` into the kernel if a test fails.
  • System Locking: Option to prevent further actions if the project is in a "RED" (failing) state.

3. Success Criteria

TODO Automatic test suite discovery logic verification

TODO Background execution of FiveAM test suite

TODO Regression event injection on failure

TODO Integration with the Self-Fix agent

Phase B: Blueprint (PROTOCOL)

1. Architectural Intent

Interfaces for background verification and kernel alerting. Source of truth is the project's `tests/` directory and the result of the test runner.

2. Semantic Interfaces

"Triggered when a project file is modified; initiates the test loop." "Executes the standard test suite for the given project."

Phase D: Build (Implementation)

Test Execution

(defun run-tests-for-project (project-name)
  "Executes the standard test suite for the given project using SBCL."
  (let* ((projects-dir (or (uiop:getenv "PROJECTS_DIR") "projects/"))
         (project-dir (format nil "~aorg-skill-~a/" projects-dir project-name))
         (test-file (format nil "~atests/test-suite.lisp" project-dir)))
    (org-agent:kernel-log "CI - Running tests for ~a..." project-name)
    (if (uiop:file-exists-p test-file)
        (multiple-value-bind (output error-output exit-code)
            (uiop:run-program (list "sbcl" "--batch" "--load" test-file "--eval" "(uiop:quit)")
                              :ignore-error-status t :output :string :error-output :string)
          (if (= exit-code 0)
              (org-agent:kernel-log "CI SUCCESS - ~a passed all tests." project-name)
              (progn
                (org-agent:kernel-log "CI FAILURE - ~a failed tests with exit code ~a" project-name exit-code)
                (org-agent:inject-stimulus 
                 `(:type :EVENT :payload (:sensor :test-failure :project ,project-name :text ,output :stderr ,error-output))))))
        (org-agent:kernel-log "CI ERROR - No test suite found for ~a at ~a" project-name test-file))))

Registration

(defskill :skill-tdd-runner
  :priority 95 ; High priority safety gate
  :trigger (lambda (context) 
             (let ((sensor (getf (getf context :payload) :sensor)))
               (or (eq sensor :buffer-update) (eq sensor :file-saved))))
  :neuro (lambda (context) nil)
  :symbolic (lambda (action context) 
              (let ((file (getf (getf context :payload) :file)))
                (when (and file (search "projects/" file))
                  (let ((parts (uiop:split-string file :separator '(#\/))))
                    (when (> (length parts) 2)
                      ;; The project name is typically the directory after "projects/"
                      (let ((dir (nth 1 (member "projects" parts :test #'string=))))
                        (when (and dir (uiop:string-prefix-p "org-skill-" dir))
                          (run-tests-for-project (subseq dir 10))))))))))