]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - reports/slice-22a/observations.lisp
Verify CTM/XTM semantic equivalence through TMDM and CXTM (Slice 22F)
[topic-maps.git] / reports / slice-22a / observations.lisp
1 ;; Read-only documentary observations. Existing Case Records, APIs, serializers
2 ;; and finite corpus resolver; no new test system and no record-result calls.
3 (require :asdf)
4 (assert (string= "2.5.4" (lisp-implementation-version)))
5 (setf *compile-verbose* nil *load-verbose* nil)
6 (defparameter *root* (uiop:ensure-directory-pathname (uiop:getenv "TOPIC_MAPS_22A_ROOT")))
7 (asdf:load-asd (merge-pathnames "topic-maps.asd" *root*))
8 (asdf:load-system "topic-maps/ctm/encoding-tests")
9 (asdf:load-system "topic-maps/xtm/tests")
10 (in-package :cl-user)
11 (setf topic-maps.ctm.tests::*cxtm-corpus* (topic-maps.test-foundation:discover-corpus))
12 (defun write-observation (filename value)
13 (with-open-file (out (merge-pathnames filename (uiop:ensure-directory-pathname (uiop:getenv "TOPIC_MAPS_22A_OUTPUT")))
14 :direction :output :if-exists :supersede :external-format :utf-8)
15 (topic-maps.test-foundation::emit-json-value value out) (terpri out)))
16 (let* ((corpus topic-maps.ctm.tests::*cxtm-corpus*) (cases (topic-maps.test-foundation:corpus-cases corpus))
17 (ids (with-open-file (in (uiop:getenv "TOPIC_MAPS_22A_IDS")) (read in)))
18 (before (mapcar #'topic-maps.registered-original.tests::case-state cases)) (rows nil))
19 (assert (= 11 (length ids)))
20 (dolist (id ids)
21 (let* ((case (first (topic-maps.test-foundation:select-cases corpus :id id)))
22 (doc (topic-maps.test-foundation:test-case-document-iri case))
23 (source (topic-maps.test-foundation:test-case-source-pathname case))
24 (raw (topic-maps.registered-original.tests::binary source))
25 (baseline (topic-maps.test-foundation:test-case-expected-baseline case))
26 (expected (when baseline (topic-maps.registered-original.tests::binary baseline)))
27 (map nil) (counter nil) (condition nil) (environments nil) (transfers nil))
28 (multiple-value-bind (resolver calls) (topic-maps.mergemap.tests::original-resources)
29 (handler-case
30 (topic-maps.include.tests::call-with-context-observer
31 (lambda (keys result final parser)
32 (push (topic-maps.test-foundation::fields
33 "documentIRI" (getf keys :document-iri) "wildcardIRI" (getf keys :wildcard-iri (getf keys :document-iri))
34 "initialCounter" (getf keys :wildcard-counter 0) "finalCounter" final
35 "templateCount" (hash-table-count (topic-maps.ctm::parser-templates parser))
36 "model" (topic-maps.template.tests::observe result)) environments))
37 (lambda () (topic-maps.include.tests::call-with-alias-observer
38 (lambda (child parent old new)
39 (push (topic-maps.test-foundation::fields "childDocumentIRI" child "parentDocumentIRI" parent "before" old "after" new) transfers))
40 (lambda () (multiple-value-setq (map counter)
41 (topic-maps.ctm:deserialize-file source :document-iri doc :source-name id :resource-resolver resolver))))))
42 (error (c) (setf condition c)))
43 (let* ((held (when map (topic-maps.import.tests::handles map)))
44 (state (when map (topic-maps.import.tests::state map held)))
45 (actual (when map (topic-maps.cxtm:canonicalize-octets map :base-locator doc))))
46 (when map
47 (assert (topic-maps.reference.tests::references-current-p map))
48 (assert (equalp actual (topic-maps.cxtm:canonicalize-octets map :base-locator doc)))
49 (assert (equal state (topic-maps.import.tests::state map held))))
50 (push (topic-maps.test-foundation::fields
51 "id" id "documentIRI" doc "sourceKey" id "sourceBytes" (length raw)
52 "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list))
53 "sourceText" (topic-maps.ctm::decode-utf8 raw)
54 "condition" (topic-maps.registered-original.tests::condition-data condition)
55 "model" (when map (topic-maps.template.tests::observe map)) "finalCounter" counter
56 "requests" (coerce (funcall calls) 'vector) "environments" (coerce (reverse environments) 'vector)
57 "aliasTransfers" (coerce (reverse transfers) 'vector)
58 "actualCXTM" (when actual (babel:octets-to-string actual :encoding :utf-8))
59 "actualBytes" (when actual (length actual)) "expectedBytes" (when expected (length expected))
60 "expectedCXTM" (when expected (babel:octets-to-string expected :encoding :utf-8))
61 "firstDifferentByte" (when (and actual expected) (mismatch actual expected))
62 "byteExact" (if (and actual expected (equalp actual expected)) :true :false)
63 "canonicalizationPreservesMap" (when map :true) "referencesCurrent" (when map :true)) rows)))))
64 (assert (equal before (mapcar #'topic-maps.registered-original.tests::case-state cases)))
65 (write-observation "ctm-observations.json" (topic-maps.test-foundation::fields
66 "kind" "read-only-original-observations-no-registration" "caseStatesUnchanged" :true "cases" (coerce (nreverse rows) 'vector))))
67 ;; Reuse all twelve already documented context probes; no originals substituted.
68 (load (merge-pathnames "reports/slice-20j/controls.lisp" *root*))
69 (assert (not topic-maps.xtm.tests::*cases*))
70 (format t "CLOSURE-OBSERVATIONS: 11 original CTM reads and 12 retained context probes; no registrations~%")