AtlatestRepositorysigil-doc
1
;;; No-execution witness probe (SD-P4).2
;;;3
;;; Inspects a manuscript whose author code PRINTS MARKERS WHEN EVALUATED, and4
;;; imports nothing from sigil-doc except the inspection surface itself -- no5
;;; `(sigil doc)`, no `(sigil doc author)`, no author runtime. If passive6
;;; inspection evaluates author expressions, loads the author module, or lowers7
;;; to generated syntax, the fixture's markers appear in this process's output8
;;; and the gate arm that runs this probe goes red.9
;;;10
;;; The arm's positive control evaluates the SAME fixture through the real11
;;; `#lang` path and requires the markers to appear, so the probe is known to be12
;;; able to see execution before it is used to assert execution's absence.13
(import (sigil core) (sigil fs) (sigil language) (sigil doc inspect))15
(define path "test/fixtures/sd-p4-witness.sgd")16
(define source (read-file-string path))17
(define header (inspect-language-source source path))18
(define tree (inspect-document-source source path (language-header-end header)))20
(define (count-nodes nodes)21
(if (null? nodes) 022
(+ 1 (count-nodes (tree-node-children (car nodes)))23
(count-nodes (cdr nodes)))))25
(define nodes (count-nodes (document-tree-roots tree)))26
(define commands27
(let walk ((pending (document-tree-roots tree)) (n 0))28
(if (null? pending) n29
(walk (append (tree-node-children (car pending)) (cdr pending))30
(if (eq? (tree-node-kind (car pending)) 'command) (+ n 1) n)))))31
(define expressions32
(let walk ((pending (document-tree-roots tree)) (n 0))33
(if (null? pending) n34
(walk (append (tree-node-children (car pending)) (cdr pending))35
(if (eq? (tree-node-kind (car pending)) 'expr) (+ n 1) n)))))37
;; The probe reports its own coverage. A witness that inspected nothing must not38
;; read as "no execution observed".39
(display "SD_P4_WITNESS_PROBE_INSPECTED nodes=")40
(display nodes)41
(display " commands=")42
(display commands)43
(display " author-expressions=")44
(display expressions)45
(newline)