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

3.4 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

(defun tdd-runner-perceive-change (project-name)
  "Triggered when a project file is modified; initiates the test loop.")

(defun tdd-runner-execute (project-name)
  "Executes the standard test suite for the given project.")

Phase D: Build (Implementation)

Test Execution

(defun tdd-runner-execute (project-name)
  (let* ((projects-dir (or (uiop:getenv "PROJECTS_DIR") "projects/"))
         (test-dir (format nil "~aorg-skill-~a/tests/" projects-dir project-name))
         (lisp-tests (format nil "~atest-suite.lisp" test-dir))
         (python-tests (format nil "~asimulate_*.py" test-dir)))
    (kernel-log "CI - Running tests for ~a..." project-name)
    ;; Mock execution: If it fails, send to the Scientist Agent
    (let ((failure-log "ERROR: Expected T but got NIL in test case 42."))
      (when failure-log
        (kernel-log "CI ERROR - Test failed in ~a. Pushing to Scientist Agent..." project-name)
        (org-agent:inject-stimulus 
         `(:type :EVENT :payload (:sensor :test-failure :project ,project-name :text ,failure-log)))))))

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/"
                      (tdd-runner-execute (nth 1 (member "projects" parts :test #'string=)))))))))