;; Read-only documentary observations. Existing Case Records, APIs, serializers ;; and finite corpus resolver; no new test system and no record-result calls. (require :asdf) (assert (string= "2.5.4" (lisp-implementation-version))) (setf *compile-verbose* nil *load-verbose* nil) (defparameter *root* (uiop:ensure-directory-pathname (uiop:getenv "TOPIC_MAPS_22A_ROOT"))) (asdf:load-asd (merge-pathnames "topic-maps.asd" *root*)) (asdf:load-system "topic-maps/ctm/encoding-tests") (asdf:load-system "topic-maps/xtm/tests") (in-package :cl-user) (setf topic-maps.ctm.tests::*cxtm-corpus* (topic-maps.test-foundation:discover-corpus)) (defun write-observation (filename value) (with-open-file (out (merge-pathnames filename (uiop:ensure-directory-pathname (uiop:getenv "TOPIC_MAPS_22A_OUTPUT"))) :direction :output :if-exists :supersede :external-format :utf-8) (topic-maps.test-foundation::emit-json-value value out) (terpri out))) (let* ((corpus topic-maps.ctm.tests::*cxtm-corpus*) (cases (topic-maps.test-foundation:corpus-cases corpus)) (ids (with-open-file (in (uiop:getenv "TOPIC_MAPS_22A_IDS")) (read in))) (before (mapcar #'topic-maps.registered-original.tests::case-state cases)) (rows nil)) (assert (= 11 (length ids))) (dolist (id ids) (let* ((case (first (topic-maps.test-foundation:select-cases corpus :id id))) (doc (topic-maps.test-foundation:test-case-document-iri case)) (source (topic-maps.test-foundation:test-case-source-pathname case)) (raw (topic-maps.registered-original.tests::binary source)) (baseline (topic-maps.test-foundation:test-case-expected-baseline case)) (expected (when baseline (topic-maps.registered-original.tests::binary baseline))) (map nil) (counter nil) (condition nil) (environments nil) (transfers nil)) (multiple-value-bind (resolver calls) (topic-maps.mergemap.tests::original-resources) (handler-case (topic-maps.include.tests::call-with-context-observer (lambda (keys result final parser) (push (topic-maps.test-foundation::fields "documentIRI" (getf keys :document-iri) "wildcardIRI" (getf keys :wildcard-iri (getf keys :document-iri)) "initialCounter" (getf keys :wildcard-counter 0) "finalCounter" final "templateCount" (hash-table-count (topic-maps.ctm::parser-templates parser)) "model" (topic-maps.template.tests::observe result)) environments)) (lambda () (topic-maps.include.tests::call-with-alias-observer (lambda (child parent old new) (push (topic-maps.test-foundation::fields "childDocumentIRI" child "parentDocumentIRI" parent "before" old "after" new) transfers)) (lambda () (multiple-value-setq (map counter) (topic-maps.ctm:deserialize-file source :document-iri doc :source-name id :resource-resolver resolver)))))) (error (c) (setf condition c))) (let* ((held (when map (topic-maps.import.tests::handles map))) (state (when map (topic-maps.import.tests::state map held))) (actual (when map (topic-maps.cxtm:canonicalize-octets map :base-locator doc)))) (when map (assert (topic-maps.reference.tests::references-current-p map)) (assert (equalp actual (topic-maps.cxtm:canonicalize-octets map :base-locator doc))) (assert (equal state (topic-maps.import.tests::state map held)))) (push (topic-maps.test-foundation::fields "id" id "documentIRI" doc "sourceKey" id "sourceBytes" (length raw) "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list)) "sourceText" (topic-maps.ctm::decode-utf8 raw) "condition" (topic-maps.registered-original.tests::condition-data condition) "model" (when map (topic-maps.template.tests::observe map)) "finalCounter" counter "requests" (coerce (funcall calls) 'vector) "environments" (coerce (reverse environments) 'vector) "aliasTransfers" (coerce (reverse transfers) 'vector) "actualCXTM" (when actual (babel:octets-to-string actual :encoding :utf-8)) "actualBytes" (when actual (length actual)) "expectedBytes" (when expected (length expected)) "expectedCXTM" (when expected (babel:octets-to-string expected :encoding :utf-8)) "firstDifferentByte" (when (and actual expected) (mismatch actual expected)) "byteExact" (if (and actual expected (equalp actual expected)) :true :false) "canonicalizationPreservesMap" (when map :true) "referencesCurrent" (when map :true)) rows))))) (assert (equal before (mapcar #'topic-maps.registered-original.tests::case-state cases))) (write-observation "ctm-observations.json" (topic-maps.test-foundation::fields "kind" "read-only-original-observations-no-registration" "caseStatesUnchanged" :true "cases" (coerce (nreverse rows) 'vector)))) ;; Reuse all twelve already documented context probes; no originals substituted. (load (merge-pathnames "reports/slice-20j/controls.lisp" *root*)) (assert (not topic-maps.xtm.tests::*cases*)) (format t "CLOSURE-OBSERVATIONS: 11 original CTM reads and 12 retained context probes; no registrations~%")