;; The existing positive/negative executor guards now use valid-but-excluded
;; Variant resourceRef for Unsupported. Old reports and their historical fixtures stay
;; unchanged. Target one real contract in a disposable fresh ASDF process.
(require :asdf)
(assert (string= "2.5.4" (lisp-implementation-version)))
(setf *compile-verbose* nil *load-verbose* nil)
(asdf:load-asd (merge-pathnames "../../topic-maps.asd" *load-truename*))
(asdf:load-system "topic-maps/xtm/tests")
(let* ((family (uiop:getenv "TOPIC_MAPS_21G_FAMILY")) (mode (uiop:getenv "TOPIC_MAPS_21G_FAULT"))
(target (cond ((string= family "positive") "xtm2/in/empty.xtm")
((string= family "negative") "xtm2/invalid/id-invalid.xtm")
((string= family "name") "xtm2/in/name.xtm")
((string= family "scope") "xtm2/in/name-scope.xtm")
((string= family "iid") "xtm2/in/itemid-name.xtm")
((string= family "variant") "xtm2/in/variant.xtm")
((string= family "variant-negative") "xtm2/invalid/variant-missing-scope-duplicate.xtm")
(t (error "Unknown control family ~S" family)))))
(if (string= mode "mismatch")
(let ((saved (symbol-function 'topic-maps.cxtm:canonicalize-octets))
(iri (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" target)))
(setf (symbol-function 'topic-maps.cxtm:canonicalize-octets)
(lambda (map &rest args)
(let ((actual (apply saved map args)))
(if (equal iri (getf args :base-locator))
(let ((changed (copy-seq actual))) (setf (aref changed 0) (logxor 1 (aref changed 0))) changed)
actual)))))
(let* ((saved (symbol-function 'topic-maps.xtm:deserialize-octets))
(source (cond ((string= mode "xml") "")
((string= mode "unsupported") (topic-maps.xtm.tests::document "N"))
((string= mode "tmdm") (topic-maps.xtm.tests::document ""))
((string= mode "xtm") (topic-maps.xtm.tests::document ""))
((string= mode "wrong-cause") (topic-maps.xtm.tests::document
(if (string= family "variant-negative")
"NV"
"")))
((string= mode "accepted") (topic-maps.xtm.tests::document ""))
(t (error "Unknown control mode ~S" mode)))))
(setf (symbol-function 'topic-maps.xtm:deserialize-octets)
(lambda (raw &rest args)
(apply saved (if (equal target (getf args :source-key)) (topic-maps.xtm.tests::bytes source) raw) args)))))
(asdf:test-system "topic-maps/xtm"))
(error "Fault injection did not cause the required ASDF failure.")