]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - reports/slice-22s/integration-preflight.lisp
examples: explore project work through native Topic Maps (slice 22U)
[topic-maps.git] / reports / slice-22s / integration-preflight.lisp
1 ;; Execute BEFORE any productive Reader edit. Only existing 22R APIs are used.
2 (require :asdf)
3 (setf *compile-verbose* nil *load-verbose* nil)
4 (assert (string= "2.5.4" (lisp-implementation-version)))
5 (asdf:load-asd (merge-pathnames "../../topic-maps.asd" *load-truename*))
6 (asdf:load-system "topic-maps/xtm/tests")
7 (in-package #:topic-maps.xtm.tests)
8 (defun sp-inventory (node &optional path)
9 (let* ((next (append path (list (list (topic-maps.xtm::node-uri node) (topic-maps.xtm::node-name node)))))
10 (here (when (and (equal (topic-maps.xtm::node-uri node) "http://www.topicmaps.org/xtm/")
11 (equal (topic-maps.xtm::node-name node) "resourceData"))
12 (list (list node next)))))
13 (append here (loop for c in (topic-maps.xtm::node-children node) unless (stringp c)
14 append (sp-inventory c next)))))
15 (let* ((source "<t:topicMap xmlns:t='http://www.topicmaps.org/xtm/' xmlns:p='urn:parent' version='2.0'><t:topic id='owner'><t:occurrence><t:type><t:topicRef href='#type'/></t:type><t:resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'><p:x/></t:resourceData></t:occurrence><t:occurrence><t:type><t:topicRef href='#type'/></t:type><t:resourceData>plain</t:resourceData></t:occurrence><t:name><t:value>N</t:value><t:variant><t:scope><t:topicRef href='#s'/></t:scope><t:resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'><f:resourceData xmlns:f='urn:foreign'>F<p:y/></f:resourceData></t:resourceData></t:variant></t:name><t:occurrence><t:type><t:topicRef href='#type'/></t:type><t:resourceData datatype='urn:custom'>custom</t:resourceData></t:occurrence></t:topic></t:topicMap>")
16 (expected '("<p:x xmlns:p=\"urn:parent\"></p:x>" "plain" "<f:resourceData xmlns:f=\"urn:foreign\" xmlns:p=\"urn:parent\">F<p:y></p:y></f:resourceData>" "custom"))
17 (results nil) (contexts nil))
18 (dolist (encoding '(:utf-8 :utf-16le :utf-16be))
19 (let* ((raw (bytes source encoding (not (eq encoding :utf-8))))
20 (snapshot (copy-seq raw)) (root (topic-maps.xml:parse-octets raw (make-instance 'topic-maps.xtm::source-handler)))
21 (inventory (sp-inventory root)) (ctx (topic-maps.xml:parse-canonical-context raw))
22 (index (make-hash-table :test #'eq)) (rows nil))
23 (assert (equalp raw snapshot))
24 (assert (= (length expected) (length inventory) (topic-maps.xml:resource-data-count ctx)))
25 (loop for entry in inventory for ordinal from 0 for want in expected do
26 (assert (not (nth-value 1 (gethash (first entry) index))))
27 (setf (gethash (first entry) index) ordinal)
28 (multiple-value-bind (value utf8) (topic-maps.xml:canonicalize-resource-data ctx :index ordinal)
29 (assert (equal want value)) (assert (equalp (bytes want) utf8))
30 (push (mm-fields "ordinal" ordinal "expandedPath" (format nil "~S" (second entry))
31 "datatype" (topic-maps.xtm::attr (first entry) "datatype") "expected" want "actual" value
32 "actualHex" (cr-hex utf8)) rows)))
33 ;; Distinct document-local source nodes cannot be looked up by EQ in a
34 ;; foreign frame, even with identical bytes, IRI or diagnostic Source Key.
35 (let* ((other (topic-maps.xml:parse-octets raw (make-instance 'topic-maps.xtm::source-handler)))
36 (other-node (first (first (sp-inventory other)))))
37 (assert (not (nth-value 1 (gethash other-node index)))))
38 (push ctx contexts)
39 (push (mm-fields "encoding" (string encoding) "inputHex" (cr-hex raw)
40 "sameOriginalBytesUnchanged" :true "sourceResourceCount" (length inventory)
41 "contextResourceCount" (topic-maps.xml:resource-data-count ctx)
42 "foreignLocalNameSkipped" :true "foreignSourceNodesNotOwned" :true
43 "rows" (coerce (nreverse rows) 'vector)) results)))
44 ;; Same resource count alone is NOT a provenance proof. Construct contexts
45 ;; exclusively in a private document-local frame from the preserved octets;
46 ;; no externally supplied opaque context is accepted by the planned Reader.
47 (let ((other (topic-maps.xml:parse-canonical-context (bytes (cq-wrap "DIFFERENT")))))
48 (assert (= 1 (topic-maps.xml:resource-data-count other))))
49 (let ((out (uiop:getenv "TOPIC_MAPS_INTEGRATION_PREFLIGHT_REPORT")))
50 (cq-write out (mm-fields "kind" "pre-Reader-edit-existing-22R-API-contract"
51 "readerEdited" :false "readerAnyTypeEnabled" :false "qualificationPassed" :true
52 "constructionContract" "private per-document frame; retained original bytes; all XTM-expanded-name resourceData nodes in preorder; EQ node ownership; no supplied contexts; cardinality and immutable bytes checked"
53 "opaqueContextProvenanceIntrospectable" :false "countAloneSufficient" :false
54 "runs" (coerce (nreverse results) 'vector))))
55 (format t "INTEGRATION-PREFLIGHT-PASS: 3 encodings; 12 independent indexed values; unchanged Reader~%"))