AtlatestRepositorysigil-doc

sigil-doc / tree / testtest-section-profile.sgl

1;;; SD-P7 -- the section-child predicate as a reader/profile parameter.
2;;;
3;;; THE MEASUREMENT THIS SUITE IS BUILT AROUND, because it changed the phase.
4;;; There are THREE closed-enumeration gates between a `@task` and a
5;;; `@section`, not one, and a manuscript NEVER REACHES `make-section`:
6;;;
7;;; 1. make-section -> require-list -> block-node?
8;;; 2. author-normalize -> document-node? (every lowered command result)
9;;; 3. author-flatten -> document-node? (every child of a flattening
10;;; container, which `@section` is)
11;;;
12;;; `@task{a}` inside a `@section` dies at gate 2 with a message naming `@task`,
13;;; not `@section`. A repair confined to `make-section` therefore satisfies a
14;;; CONVERTER that builds records programmatically and does not satisfy a
15;;; READER -- and the reason this phase sits on F1b's critical path is
16;;; precisely that a reader which cannot build a `## Tasks` note cannot read the
17;;; estate. So the end-to-end arm below is the load-bearing one, and the unit
18;;; arms exist to say WHY it passes.
19;;;
20;;; TWO INSTRUMENT COMMITMENTS.
21;;;
22;;; * The end-to-end arms go through the REAL `#lang` path -- the compiler
23;;; resolves `#lang sd-p7/folio` to `(sd-p7 folio reader)` and calls its
24;;; `read-language-source` -- and never through runtime `eval` of parsed
25;;; forms. SD-P1's headline finding about keyword formals turned out to be
26;;; an artifact of exactly that harness.
27;;; * Every refusal arm carries a POSITIVE CONTROL in the same `let`: the same
28;;; profile, the same section, the same manuscript, with the one offending
29;;; value replaced by a legal one. An arm that passed because the predicate
30;;; rejects everything, or because the manuscript never loaded, cannot be
31;;; green here.
32(import (sigil test) (sigil syntax) (sigil fs) (sigil string)
33 (sigil doc) (sigil doc author) (sigil doc private author-runtime)
34 (sd-p7 folio model))
36;; ---------------------------------------------------------------- helpers
38(define L (make-srcloc "sd-p7-suite" 1 1 0 0))
40(define (message thunk)
41 (guard (exn (else (exception-message exn))) (thunk) "NO ERROR"))
43(define (contains? haystack needle)
44 (let ((n (string-length haystack)) (m (string-length needle)))
45 (let loop ((i 0))
46 (cond ((> (+ i m) n) #f)
47 ((string=? (substring haystack i (+ i m)) needle) #t)
48 (else (loop (+ i 1)))))))
50;; The 1-based line of the UNIQUE line in `path` containing `needle`, so a
51;; located-diagnostic assertion never restates a number the fixture already
52;; knows. Raises when the needle is absent OR repeated: a fixture edit that made
53;; the anchor ambiguous would otherwise move the assertion to a different node
54;; silently. Derived at test time, like the fixture offsets in test-root-profile.
55(define (line-of path needle)
56 (let loop ((lines (string-split (read-file-string path) "\n")) (n 1) (found #f))
57 (cond ((null? lines)
58 (if found found (error (string-append "anchor not found in " path ": " needle))))
59 ((contains? (car lines) needle)
60 (if found (error (string-append "anchor is ambiguous in " path ": " needle))
61 (loop (cdr lines) (+ n 1) n)))
62 (else (loop (cdr lines) (+ n 1) found)))))
64;; "<file>:<line>:" as the diagnostic would spell it, built from the fixture.
65(define (located path needle)
66 (let ((slash (let scan ((i (- (string-length path) 1)))
67 (cond ((< i 0) -1)
68 ((char=? (string-ref path i) #\/) i)
69 (else (scan (- i 1)))))))
70 (string-append (substring path (+ slash 1) (string-length path))
71 ":" (number->string (line-of path needle)) ":")))
73(define (a-paragraph) (make-paragraph (list (make-text "prose" L)) L))
74(define (a-title) (list (make-text "Tasks" L)))
76(define (a-task) (make-task "t-one" "A work item" '() L))
77(define (a-related) (make-related "topics/other" 'mentions L))
78(define (a-milestone) (make-milestone "m-one" "A structural container" '() L))
79(define (a-phase) (make-phase "p-one" "A structural container" '() L))
81;; Sections successfully built through a PROFILE, printed so the gate can assert
82;; the walk was not empty. Arms that construct nothing must never read as a pass.
83(define sections-built 0)
84(define (built-section profile children)
85 (let ((s (make-section-with-profile profile "tasks" (a-title) children L)))
86 (set! sections-built (+ sections-built 1))
87 s))
89;; The manuscript is loaded ONCE, inside the arm that needs it first, and its
90;; document is stashed. `load` evaluates into the CALLER's module, so a second
91;; load of a different manuscript would rebind `document` underneath any arm
92;; still using it.
93(define folio-note #f)
94(define (folio-note-document)
95 (if folio-note folio-note
96 (begin (load "test/fixtures/sd-p7-folio-note.sgd")
97 (set! folio-note (eval 'document))
98 folio-note)))
100(define (section-named doc id)
101 (let loop ((xs (note-children doc)))
102 (cond ((null? xs) (error (string-append "no section with id " id)))
103 ((and (section? (car xs)) (string=? (section-id (car xs)) id)) (car xs))
104 (else (loop (cdr xs))))))
106(define (count-matching pred xs)
107 (let loop ((rest xs) (n 0))
108 (if (null? rest) n (loop (cdr rest) (if (pred (car rest)) (+ n 1) n)))))
110;; ---------------------------------------------------------------- suite
112(test "a folio-shaped profile builds a @section holding @task children, end to end"
113 ;; THE ACCEPTANCE CRITERION, through `#lang` and `load` rather than `eval`.
114 (let* ((doc (folio-note-document))
115 (tasks (section-named doc "tasks"))
116 (notes (section-named doc "notes"))
117 (children (section-children tasks)))
118 (assert-true (note? doc))
119 (assert-equal "topics/sd-p7-section-child" (note-id doc))
120 ;; Shape asserted BEFORE anything indexes into it, so a wrong shape reports
121 ;; as a failed count rather than as a `car` type error somewhere downstream.
122 (assert-equal 4 (length children))
123 ;; POSITIVE CONTROL, first: ordinary core blocks are still section children.
124 ;; A profile that admitted work items by admitting EVERYTHING would satisfy
125 ;; the task assertions below just as well as the correct one, and this is
126 ;; the assertion it cannot fake, because `paragraph?` is a core kind whose
127 ;; admission is the anti-narrowing floor.
128 (assert-equal 1 (count-matching paragraph? children))
129 ;; ...and the work items and the relational node are there, which is the
130 ;; thing that was impossible before this phase.
131 (assert-equal 2 (count-matching task? children))
132 (assert-equal 1 (count-matching related? children))
133 (assert-equal "t-predicate" (task-id (cadr children)))
134 (assert-equal "t-witnesses" (task-id (caddr children)))
135 ;; A task's own body survives, so the node is a real record and not an
136 ;; opaque value that merely got past a predicate.
137 (assert-equal 1 (length (task-children (cadr children))))
138 ;; LOCATIONS. A delegating language must get exact manuscript locations, not
139 ;; a synthesized placeholder: that is the whole reason it delegates the
140 ;; grammar instead of forking it.
141 (let ((loc (section-location tasks)))
142 (assert-equal "test/fixtures/sd-p7-folio-note.sgd" (srcloc-file loc))
143 (assert-true (> (srcloc-line loc) 1))
144 (assert-true (> (srcloc-span loc) 0)))
145 ;; A SECOND section, so the arm exercises a set rather than one node and a
146 ;; bug that only ever populated the first would show.
147 (assert-equal 1 (count-matching task? (section-children notes)))))
149(test "a structural container is refused as a section child, and a work item is not"
150 ;; CONDITION 3 at the product layer, in both directions and at both entry
151 ;; points a language can use.
152 (let ((profile folio-content-profile))
153 ;; Accepted: work item, relational node, core block.
154 (assert-equal 3 (length (section-children
155 (built-section profile (list (a-paragraph) (a-task) (a-related))))))
156 ;; Refused: milestone and phase, each named separately -- Fable's condition
157 ;; names two kinds and an arm that checked one would be half a check.
158 ;;
159 ;; The wording is the FOLIO profile's, because that profile supplies a
160 ;; describer. This arm used to assert the model's generic text and went red
161 ;; the moment the describer landed, which is the arm doing its job: the
162 ;; message a delegating language emits is part of what it delegates, and an
163 ;; arm pinning the wrong one would have hidden the describer never running.
164 ;; Each assertion checks the CLASS NAME and the LOCATION separately, so a
165 ;; describer that produced only one of them cannot pass.
166 (let ((milestone-message (message (lambda () (make-section-with-profile
167 profile "tasks" (a-title)
168 (list (a-paragraph) (a-milestone)) L))))
169 (phase-message (message (lambda () (make-section-with-profile
170 profile "tasks" (a-title)
171 (list (a-paragraph) (a-phase)) L)))))
172 (assert-true (contains? milestone-message "a section may not contain a structural container"))
173 (assert-true (contains? phase-message "a section may not contain a structural container"))
174 (assert-true (contains? milestone-message "sd-p7-suite:1:1:"))
175 (assert-true (contains? phase-message "sd-p7-suite:1:1:")))
176 ;; The predicate itself, asked directly, so a failure above is attributable
177 ;; to the predicate rather than to `make-section`'s plumbing.
178 (assert-true (folio-section-child? (a-task)))
179 (assert-true (folio-section-child? (a-related)))
180 (assert-true (folio-section-child? (a-paragraph)))
181 (assert-true (not (folio-section-child? (a-milestone))))
182 (assert-true (not (folio-section-child? (a-phase))))))
184(test "a manuscript cannot launder a structural container through a section"
185 ;; THE GEOMETRY IS THE POINT, and the first version of this arm had it wrong.
186 ;; It put the section directly under the root, which tests a real rule and not
187 ;; the laundering one. Laundering is `@task{ @section{ @milestone } }`: a
188 ;; section INSIDE a work item, re-nesting a structural container back
189 ;; underneath it. A fixture in the wrong geometry passes while testing
190 ;; something else, which is the expensive kind of wrong.
191 ;;
192 ;; Both structural containers, separately: the rule names two and an arm that
193 ;; checked one would be half a check.
194 (let ((milestone-raised (message (lambda () (load "test/fixtures/sd-p7-folio-laundering.sgd"))))
195 (phase-raised (message (lambda () (load "test/fixtures/sd-p7-folio-laundering-phase.sgd")))))
196 (assert-true (not (contains? milestone-raised "NO ERROR")))
197 (assert-true (not (contains? phase-raised "NO ERROR")))
198 ;; The diagnostic NAMES THE RULE, in the delegating language's own
199 ;; vocabulary, rather than merely failing.
200 (assert-true (contains? milestone-raised "a section may not contain a structural container"))
201 (assert-true (contains? phase-raised "a section may not contain a structural container"))
202 ;; ...and LOCATES THE OFFENDING CHILD, not the section that contains it. A
203 ;; section holding prose plus four children would otherwise say "something
204 ;; in here is wrong" and leave the author to guess which.
205 (assert-true (contains? milestone-raised
206 (located "test/fixtures/sd-p7-folio-laundering.sgd" "@milestone[")))
207 (assert-true (contains? phase-raised
208 (located "test/fixtures/sd-p7-folio-laundering-phase.sgd" "@phase[")))))
210(test "the section-child predicate applies at every depth, not only the outermost"
211 ;; A3. WHAT THIS ARM CAN AND CANNOT SHOW, stated because the difference is not
212 ;; obvious. It goes red when the predicate stops refusing structural
213 ;; containers (sabotage legs 2, 6 and 7 all redden it), so it is not vacuous.
214 ;; It CANNOT be reddened independently of the single-level arm, because the
215 ;; depth property here is STRUCTURAL: `@section` builds inside-out and each
216 ;; section validates its own children at its own construction, so there is no
217 ;; traversal that could check the top level and skip deeper ones. A leg
218 ;; planting exactly that shortcut left both arms green, measured.
219 ;;
220 ;; It is therefore regression insurance against a future implementation that
221 ;; DOES walk a finished tree, rather than a gate on todays code.
222 ;;
223 ;; An implementation that checked the top section and passed raw children
224 ;; below satisfies every single-level fixture and launders at depth two. In
225 ;; this fixture the OUTER section's own children are all legal, so whatever
226 ;; refuses it must have looked deeper.
227 (let ((raised (message (lambda () (load "test/fixtures/sd-p7-folio-depth.sgd")))))
228 (assert-true (not (contains? raised "NO ERROR")))
229 (assert-true (contains? raised "a section may not contain a structural container"))
230 ;; Located at the INNER milestone, which is the whole claim of this arm.
231 (assert-true (contains? raised
232 (located "test/fixtures/sd-p7-folio-depth.sgd" "@milestone[")))))
234(test "the default language still refuses a foreign child under a section, from a manuscript"
235 ;; A4. Every other fixture in front of me is folio-shaped, so this is the
236 ;; direction nobody is watching: parameterizing the predicate must not move
237 ;; plain `#lang sigil/doc`. Asserted END TO END from a manuscript, not only at
238 ;; the constructor, because the constructor is not the path an author takes.
239 (let ((raised (message (lambda () (load "test/fixtures/sd-p7-sigil-doc-section.sgd")))))
240 (assert-true (not (contains? raised "NO ERROR")))
241 ;; The manuscript dies at `author-normalize` -- the FIRST of the three
242 ;; closed enumerations, before `make-section` is ever reached. That is the
243 ;; measured behaviour this phase started from and it must not have changed.
244 (assert-true (contains? raised "must produce a document node or proper list of nodes"))
245 ;; ...and the fixture's legal sibling proves the section still accepts
246 ;; ordinary blocks, so this arm cannot pass by refusing everything.
247 (assert-true (contains? raised "@task"))))
249(test "a profile that admits a refused witness cannot be constructed"
250 ;; CONDITION 3 AS A MECHANISM. The arm above catches today's profile; this
251 ;; catches every profile anyone writes later, including a future widening of
252 ;; folio's own, at the line that writes it.
253 (let ((admitted (list (a-task) (a-related)))
254 (refused (list (a-milestone) (a-phase))))
255 ;; A predicate that admits structural containers -- the laundering shape.
256 (assert-error
257 (make-content-profile "folio/doc" folio-node?
258 (lambda (x) (or (block-node? x) (folio-work-item? x)
259 (folio-relational-node? x) (folio-structural-container? x)))
260 admitted refused))
261 ;; ...and the message names what happened rather than merely failing.
262 (assert-true
263 (contains? (message (lambda () (make-content-profile "folio/doc" folio-node?
264 (lambda (x) (or (folio-section-child? x) (milestone? x)))
265 admitted refused)))
266 "admits a witness the profile declares refused"))
267 ;; POSITIVE CONTROL: the identical call with the correct predicate
268 ;; constructs. Without this the assertions above would hold just as well
269 ;; against a constructor that refused every profile.
270 (assert-true (content-profile?
271 (make-content-profile "folio/doc" folio-node?
272 folio-section-child? admitted refused)))))
274(test "a profile may widen the section child set but never narrow it"
275 ;; The core block vocabulary is a floor. Without this a delegating profile
276 ;; could quietly forbid paragraphs inside sections, and `sigil/doc` documents
277 ;; would mean different things depending on whose profile was installed.
278 (let ((admitted (list (a-task)))
279 (refused (list (a-milestone))))
280 (assert-true
281 (contains? (message (lambda () (make-content-profile "narrow/doc" folio-node?
282 ;; everything folio admits, MINUS anchors
283 (lambda (x) (and (folio-section-child? x) (not (anchor? x))))
284 admitted refused)))
285 "never narrow it"))
286 ;; POSITIVE CONTROL: restore the one kind and the same profile constructs.
287 (assert-true (content-profile?
288 (make-content-profile "narrow/doc" folio-node?
289 folio-section-child? admitted refused)))))
291(test "the constructor refuses the values that would make its own checks vacuous"
292 ;; THE ANTI-VACUITY GUARD, and it is the one that makes the rest worth
293 ;; anything. Without it a profile could declare a bare symbol refused --
294 ;; refused by every sane predicate, so the refusal check passes for free --
295 ;; while its predicate admitted whatever it liked.
296 (let ((child? folio-section-child?))
297 (assert-true
298 (contains? (message (lambda () (make-content-profile "folio/doc" folio-node? child?
299 (list (a-task)) (list 'a-bare-symbol))))
300 "must satisfy the profile's own node predicate"))
301 (assert-true
302 (contains? (message (lambda () (make-content-profile "folio/doc" folio-node? child?
303 (list 'a-bare-symbol) (list (a-milestone)))))
304 "must satisfy the profile's own node predicate"))
305 ;; An empty witness list makes every check below it pass over nothing.
306 (assert-error (make-content-profile "folio/doc" folio-node? child?
307 '() (list (a-milestone))))
308 (assert-error (make-content-profile "folio/doc" folio-node? child?
309 (list (a-task)) '()))
310 ;; A predicate that RAISES rather than answering would turn every section
311 ;; construction into a crash far from the profile that caused it.
312 (assert-error (make-content-profile "folio/doc" folio-node?
313 (lambda (x) (error "I refuse to answer"))
314 (list (a-task)) (list (a-milestone))))
315 ;; A NON-LIST `refused`. Covered by nothing until adversarial review asked
316 ;; which clauses had no arm: without the clause, the improper tail reaches
317 ;; `(append admitted refused)` and dies as a `car` type error deep inside a
318 ;; helper rather than as a named refusal.
319 (assert-error (make-content-profile "folio/doc" folio-node? child?
320 (list (a-task)) (a-milestone)))
321 ;; A WITNESS DECLARED BOTH WAYS. This always failed one of the two predicate
322 ;; checks, but reported whichever the predicate happened to land on -- a
323 ;; message about the PREDICATE for a defect in the DECLARATION.
324 (let ((both (a-task)))
325 (assert-true
326 (contains? (message (lambda () (make-content-profile "folio/doc" folio-node? child?
327 (list both) (list both))))
328 "both admitted and refused")))
329 ;; THE `admitted` CHECK, REACHED. Every profile in this tree satisfies it
330 ;; trivially -- the suite's profiles all widen `folio-section-child?`, and
331 ;; `sigil-doc-content-profile` declares the core witnesses it is already
332 ;; required to admit -- so nothing exercised it. A profile whose predicate
333 ;; is narrower than its own declaration does.
334 (assert-true
335 (contains? (message (lambda () (make-content-profile "folio/doc" folio-node? block-node?
336 (list (a-task)) (list (a-milestone)))))
337 "refuses a witness the profile declares admitted"))
338 ;; Shape validation, each spelling separately.
339 (assert-error (make-content-profile "" folio-node? child?
340 (list (a-task)) (list (a-milestone))))
341 (assert-error (make-content-profile 'folio folio-node? child?
342 (list (a-task)) (list (a-milestone))))
343 (assert-error (make-content-profile "folio/doc" 'not-a-procedure child?
344 (list (a-task)) (list (a-milestone))))
345 (assert-error (make-content-profile "folio/doc" folio-node? 'not-a-procedure
346 (list (a-task)) (list (a-milestone))))
347 (assert-error (make-content-profile "folio/doc" folio-node? child?
348 (a-task) (list (a-milestone))))
349 ;; ...and a well-formed one is still accepted, so none of the above is
350 ;; passing because the constructor refuses everything.
351 (assert-true (content-profile? (make-content-profile "folio/doc" folio-node? child?
352 (list (a-task)) (list (a-milestone)))))))
354(test "a profile's predicates must be able to say no"
355 ;; THE FLOOR ON REFUSAL, added after adversarial review defeated the witness
356 ;; apparatus in the obvious way. The vocabulary guard requires every declared
357 ;; witness to satisfy `node-predicate` -- and `(lambda (x) #t)` satisfies that
358 ;; for free, after which a profile may declare a bare symbol refused, pass
359 ;; every check, and install a vocabulary under which ANY value is a node.
360 ;; Declaring a junk PREDICATE reaches the same place as declaring a junk
361 ;; WITNESS, which is the hole the guard existed to close.
362 (assert-true
363 (contains? (message (lambda () (make-content-profile "evil/doc"
364 (lambda (x) #t)
365 (lambda (x) (not (eq? x 'sentinel)))
366 (list 'anything) (list 'sentinel))))
367 "not a document node under any profile"))
368 ;; ...and the section-child predicate is held to the same floor, separately,
369 ;; so a profile cannot pass by having only ONE discriminating predicate.
370 (assert-true
371 (contains? (message (lambda () (make-content-profile "evil/doc" folio-node?
372 (lambda (x) (not (eq? x 'sentinel)))
373 (list (a-task)) (list 'sentinel))))
374 "not a document node under any profile"))
375 ;; THE FLOOR APPLIES IN BOTH DIRECTIONS. A profile may not declare a core
376 ;; block node refused. Without this, a predicate discriminating by IDENTITY
377 ;; honours the refusal and still passes the anti-narrowing check, because that
378 ;; check builds fresh witnesses that are never `eq?` to the declared value.
379 (let ((p (a-paragraph)))
380 (assert-true
381 (contains? (message (lambda () (make-content-profile "narrowing/doc" document-node?
382 (lambda (x) (and (block-node? x) (not (eq? x p))))
383 (list (make-code-block "sigil" "1" L)) (list p))))
384 "may not declare a core block node refused")))
385 ;; POSITIVE CONTROLS. The floor must not reject a legitimate profile, and the
386 ;; core witness list the anti-narrowing rule uses must itself pass the floor.
387 (assert-true (content-profile? (make-content-profile "folio/doc" folio-node?
388 folio-section-child?
389 (list (a-task)) (list (a-milestone)))))
390 (assert-true (content-profile? sigil-doc-content-profile)))
392(test "sigil/doc's own profile is today's policy, and its seam is unchanged"
393 ;; Measured at the seam. The tree-level measurement -- every manuscript's
394 ;; canonical document, compared byte for byte against a pre-change baseline --
395 ;; is `test/sd-p7-construction-dump.sh` and lives in the gate, because
396 ;; equality over 22 documents is not something a suite assertion can carry.
397 (assert-equal "sigil/doc" (content-profile-name sigil-doc-content-profile))
398 ;; The default's predicates ARE the two historical constants. Asserted
399 ;; behaviourally over both a positive and a negative case rather than by
400 ;; identity, because identity would still hold if the wrong one were stored.
401 (let ((node? (content-profile-node-predicate sigil-doc-content-profile))
402 (child? (content-profile-section-child-predicate sigil-doc-content-profile)))
403 (assert-true (node? (a-paragraph)))
404 (assert-true (node? (make-text "x" L)))
405 (assert-true (not (node? (a-task))))
406 (assert-true (child? (a-paragraph)))
407 (assert-true (not (child? (make-text "x" L))))
408 (assert-true (not (child? (a-task)))))
409 ;; The four-argument `make-section` still refuses a foreign child with the
410 ;; message it has always raised, and the profile-aware spelling agrees with it
411 ;; to the byte under the default profile.
412 (assert-equal "make-section: child belongs to the wrong semantic category"
413 (message (lambda () (make-section "s" (a-title) (list (a-task)) L))))
414 (assert-equal "make-section: child belongs to the wrong semantic category"
415 (message (lambda () (make-section-with-profile
416 sigil-doc-content-profile "s" (a-title)
417 (list (a-task)) L))))
418 ;; The other refusals `make-section` owns are unchanged and still precede in
419 ;; the same order: an invalid id is reported before the children are examined.
420 (assert-equal "make-section: invalid id"
421 (message (lambda () (make-section "Bad Id" (a-title) (list (a-task)) L))))
422 (assert-equal "make-section: child list must not be empty"
423 (message (lambda () (make-section "s" (a-title) '() L))))
424 ;; A non-profile must not be accepted as one.
425 (assert-error (make-section-with-profile 'not-a-profile "s" (a-title)
426 (list (a-paragraph)) L))
427 ;; The core witness set the anti-narrowing rule runs over is non-empty and is
428 ;; genuinely core. The gate separately derives its expected SIZE from
429 ;; `block-node?`'s own definition, so adding a kind cannot leave the floor
430 ;; silently short.
431 (let ((witnesses (core-block-witnesses)))
432 (assert-true (> (length witnesses) 0))
433 (assert-equal (length witnesses) (count-matching block-node? witnesses))
434 (display "SD_P7_CORE_WITNESSES ") (display (length witnesses)) (newline)))
436(test "a profile without a describer emits today's wording, unlocated"
437 ;; THE DESCRIBER MUST NOT REACH THE DEFAULT PATH, and this arm has two jobs
438 ;; because under this design the describer is the ONLY thing that can add a
439 ;; location. So a leak shows up as a location appearing where there was none,
440 ;; which is a sharper signature than a string diff.
441 ;;
442 ;; JOB 1: byte-identical wording.
443 (let ((default-message (message (lambda () (make-section "s" (a-title) (list (a-task)) L))))
444 (profile-message (message (lambda () (make-section-with-profile
445 sigil-doc-content-profile "s" (a-title)
446 (list (a-task)) L)))))
447 (assert-equal "make-section: child belongs to the wrong semantic category" default-message)
448 (assert-equal "make-section: child belongs to the wrong semantic category" profile-message)
449 ;; JOB 2: NO LOCATION. The witness srcloc's file is "sd-p7-suite"; if the
450 ;; describer path ever leaked into the default, a prefix naming that file
451 ;; would appear here.
452 (assert-true (not (contains? default-message "sd-p7-suite")))
453 (assert-true (not (contains? profile-message "sd-p7-suite")))
454 (assert-true (not (contains? default-message ":1:1:")))
455 (assert-true (not (contains? profile-message ":1:1:"))))
456 ;; The default profile genuinely has no describer, asserted rather than
457 ;; inferred from the wording.
458 (assert-true (not (content-profile-describer sigil-doc-content-profile)))
459 ;; POSITIVE CONTROL ON THIS ARM: a profile that DOES supply a describer gets
460 ;; its own wording AND a location, so the two assertions above are not passing
461 ;; because the describer mechanism is inert.
462 (assert-true (content-profile-describer folio-content-profile))
463 (let ((described (message (lambda () (make-section-with-profile
464 folio-content-profile "s" (a-title)
465 (list (a-milestone)) L)))))
466 (assert-true (contains? described "a section may not contain a structural container"))
467 (assert-true (contains? described "sd-p7-suite:1:1:"))))
469(test "a describer produces wording only, and cannot make a refused child acceptable"
470 ;; The property a future editor is most likely to erode. A describer that
471 ;; returns a cheerful string, or raises, or returns a non-string, changes the
472 ;; MESSAGE and never the VERDICT.
473 (let ((liar (make-content-profile "liar/doc" folio-node? folio-section-child?
474 (list (a-task)) (list (a-milestone))
475 describer: (lambda (node) "everything is fine"))))
476 ;; Still refused, with the describer's wording.
477 (assert-equal "make-section: everything is fine"
478 (message (lambda () (make-section-with-profile
479 liar "s" (a-title) (list (a-milestone)) L))))
480 ;; ...and a legal child is still accepted, so the describer has not turned
481 ;; the constructor into something that refuses everything either.
482 (assert-equal 1 (length (section-children
483 (make-section-with-profile liar "s" (a-title)
484 (list (a-task)) L)))))
485 ;; A describer that RAISES falls back to the model's own wording rather than
486 ;; being allowed to produce nothing -- and the refusal still happens.
487 (let ((thrower (make-content-profile "thrower/doc" folio-node? folio-section-child?
488 (list (a-task)) (list (a-milestone))
489 describer: (lambda (node)
490 (if (milestone? node) "ok" (error "boom"))))))
491 (assert-equal "make-section: child belongs to the wrong semantic category"
492 (message (lambda () (make-section-with-profile
493 thrower "s" (a-title) (list (a-phase)) L)))))
494 ;; Validated where it is written: a non-procedure, and a describer that cannot
495 ;; produce wording for the profile's OWN declared refusals.
496 (assert-error (make-content-profile "bad/doc" folio-node? folio-section-child?
497 (list (a-task)) (list (a-milestone))
498 describer: "not a procedure"))
499 (assert-error (make-content-profile "bad/doc" folio-node? folio-section-child?
500 (list (a-task)) (list (a-milestone))
501 describer: (lambda (node) #f))))
503(test "installation is one-directional: entering an extent inherits, leaving restores"
504 ;; THE ASYMMETRY IS DELIBERATE, SO IT IS ASSERTED RATHER THAN MERELY TRUE.
505 ;; Fable ruled it accepted; an accepted behaviour that nothing pins is
506 ;; indistinguishable from an oversight the next reader will "fix".
507 ;;
508 ;; LEAVING is symmetric and complete: the arm below this one covers normal
509 ;; exit and the raising path.
510 ;;
511 ;; ENTERING is not. Nothing installs a profile on the way in, so code running
512 ;; inside a delegating language's extent sees THAT language's profile even if
513 ;; it is doing something `sigil/doc` would do. This asserts exactly that.
514 (with-content-profile folio-content-profile
515 (lambda ()
516 ;; Inside folio's extent, the ambient profile is folio's -- not
517 ;; `sigil-doc-content-profile` -- and a folio work item is therefore a
518 ;; legal section child HERE.
519 (assert-equal "folio/doc" (content-profile-name (author-content-profile)))
520 (assert-true (section? (make-section-with-profile (author-content-profile)
521 "inherited" (a-title)
522 (list (a-task)) L)))))
523 ;; ...and the moment the extent ends, the default is back.
524 (assert-equal "sigil/doc" (content-profile-name (author-content-profile)))
525 ;; WHY THE ASYMMETRY IS SAFE, asserted rather than argued: the anti-narrowing
526 ;; floor makes any profile a SUPERSET of the core block vocabulary, so an
527 ;; inherited ambient profile can never REFUSE something the default would have
528 ;; admitted. Checked over the whole core floor, not a sample of one.
529 (let ((folio-child? (content-profile-section-child-predicate folio-content-profile))
530 (default-child? (content-profile-section-child-predicate sigil-doc-content-profile)))
531 (let loop ((witnesses (core-block-witnesses)) (checked 0))
532 (if (null? witnesses)
533 (assert-true (> checked 0))
534 (begin
535 (assert-true (default-child? (car witnesses)))
536 (assert-true (folio-child? (car witnesses)))
537 (loop (cdr witnesses) (+ checked 1))))))
538 ;; ...and the direction that would be dangerous is the one that cannot happen:
539 ;; a foreign node the wider profile admits is still unbuildable from a
540 ;; `sigil/doc` manuscript, because that manuscript has no vocabulary for it.
541 ;; The A4 arm above proves that end to end from a real manuscript.
542 (assert-true (not ((content-profile-section-child-predicate sigil-doc-content-profile)
543 (a-task)))))
545(test "the ambient profile is restored, including when the thunk raises"
546 ;; `with-content-profile` is `dynamic-wind`-based for the same reason
547 ;; `author-at` is: a manuscript that fails half way through must not leave a
548 ;; delegating language's profile installed for whatever runs next. The raise
549 ;; case is the one a plain save-and-restore gets wrong.
550 (assert-equal "sigil/doc" (content-profile-name (author-content-profile)))
551 (with-content-profile folio-content-profile
552 (lambda () (assert-equal "folio/doc" (content-profile-name (author-content-profile)))))
553 (assert-equal "sigil/doc" (content-profile-name (author-content-profile)))
554 (guard (exn (else #t))
555 (with-content-profile folio-content-profile
556 (lambda () (error "deliberate failure inside an installed profile"))))
557 (assert-equal "sigil/doc" (content-profile-name (author-content-profile)))
558 ;; ...and only a profile may be installed.
559 (assert-error (with-content-profile 'not-a-profile (lambda () #t))))
561(test "loading a delegating language does not widen sigil/doc"
562 ;; THE HAZARD AMBIENT STATE ACTUALLY CARRIES. `(sd-p7 folio author)` has been
563 ;; loaded and a folio manuscript evaluated by the time this runs, so if the
564 ;; profile were installed globally rather than for a dynamic extent, a
565 ;; `#lang sigil/doc` manuscript would silently start accepting folio nodes.
566 ;;
567 ;; This arm is ordered LAST on purpose and depends on the end-to-end arm
568 ;; having already run; it asserts that dependency rather than assuming it.
569 (assert-true folio-note)
570 (assert-equal "sigil/doc" (content-profile-name (author-content-profile)))
571 (assert-equal "make-section: child belongs to the wrong semantic category"
572 (message (lambda () (make-section "s" (a-title) (list (a-task)) L))))
573 (assert-true (not ((content-profile-node-predicate sigil-doc-content-profile) (a-task)))))
575(test "the suite built a non-empty set of sections through a profile"
576 ;; A denominator, printed into the gate transcript. Every profile-built
577 ;; section above goes through `built-section`; if that ever collapsed to
578 ;; nothing the refusal arms would still pass in silence.
579 (display "SD_P7_SECTIONS_BUILT ") (display sections-built) (newline)
580 (assert-true (>= sections-built 1)))