AtlatestRepositorysigil-doc

sigil-doc / tree / testsd-p4-witness-probe.sgl

1;;; No-execution witness probe (SD-P4).
2;;;
3;;; Inspects a manuscript whose author code PRINTS MARKERS WHEN EVALUATED, and
4;;; imports nothing from sigil-doc except the inspection surface itself -- no
5;;; `(sigil doc)`, no `(sigil doc author)`, no author runtime. If passive
6;;; inspection evaluates author expressions, loads the author module, or lowers
7;;; to generated syntax, the fixture's markers appear in this process's output
8;;; and the gate arm that runs this probe goes red.
9;;;
10;;; The arm's positive control evaluates the SAME fixture through the real
11;;; `#lang` path and requires the markers to appear, so the probe is known to be
12;;; 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) 0
22 (+ 1 (count-nodes (tree-node-children (car nodes)))
23 (count-nodes (cdr nodes)))))
25(define nodes (count-nodes (document-tree-roots tree)))
26(define commands
27 (let walk ((pending (document-tree-roots tree)) (n 0))
28 (if (null? pending) n
29 (walk (append (tree-node-children (car pending)) (cdr pending))
30 (if (eq? (tree-node-kind (car pending)) 'command) (+ n 1) n)))))
31(define expressions
32 (let walk ((pending (document-tree-roots tree)) (n 0))
33 (if (null? pending) n
34 (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 not
38;; 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)