|
| 1 | +cmake_minimum_required(VERSION 3.20) |
| 2 | + |
| 3 | +# This collection is independent native evidence, not a claim of generated-target parity. |
| 4 | +function(verify_matlab_validator_observations observations revision matlab_version) |
| 5 | + foreach(field schemaVersion matlabRelease matlabVersion sourceRevision) |
| 6 | + string(JSON value ERROR_VARIABLE error GET "${observations}" ${field}) |
| 7 | + if(NOT error STREQUAL "NOTFOUND") |
| 8 | + message(FATAL_ERROR "Invalid native validator provenance: ${field}") |
| 9 | + endif() |
| 10 | + if(field STREQUAL "schemaVersion" AND NOT value STREQUAL "1") |
| 11 | + message(FATAL_ERROR "Invalid native validator schema") |
| 12 | + elseif(field STREQUAL "matlabRelease" AND NOT value STREQUAL "R2024b") |
| 13 | + message(FATAL_ERROR "Native validator evidence requires R2024b") |
| 14 | + elseif(field STREQUAL "matlabVersion" AND NOT value STREQUAL matlab_version) |
| 15 | + message(FATAL_ERROR "Native validator runtime differs from the reference provenance") |
| 16 | + elseif(field STREQUAL "sourceRevision" AND NOT value STREQUAL revision) |
| 17 | + message(FATAL_ERROR "Native validator revision differs from the reference provenance") |
| 18 | + endif() |
| 19 | + endforeach() |
| 20 | + set(expected_keys |
| 21 | + numeric numeric_or_logical floating real finite |
| 22 | + non_nan positive nonpositive nonnegative negative |
| 23 | + nonzero integer nonempty scalar_or_empty vector |
| 24 | + row column matrix nonmissing nonzero_length_text |
| 25 | + text text_scalar valid_variable_name greater_than greater_than_or_equal |
| 26 | + less_than less_than_or_equal in_range positive-complex positive-text |
| 27 | + integer-complex integer-text finite-text nonmissing-text nonzero-length-text-type |
| 28 | + valid-variable-name-type greater-than-complex greater-than-text nonzero-length-text-empty-double text-scalar-char-matrix |
| 29 | + range-exclusive range-exclude-lower range-exclude-upper |
| 30 | + ) |
| 31 | + set(contexts direct input output) |
| 32 | + list(LENGTH expected_keys key_count) |
| 33 | + math(EXPR expected_count "${key_count} * 3") |
| 34 | + string(JSON count ERROR_VARIABLE error LENGTH "${observations}" cases) |
| 35 | + if(NOT error STREQUAL "NOTFOUND" OR NOT count EQUAL expected_count) |
| 36 | + message(FATAL_ERROR "Native validator observation inventory is incomplete") |
| 37 | + endif() |
| 38 | + set(index 0) |
| 39 | + foreach(key IN LISTS expected_keys) |
| 40 | + foreach(context IN LISTS contexts) |
| 41 | + foreach(field name validator context exceptionIdentifier exceptionMessage) |
| 42 | + string(JSON field_type ERROR_VARIABLE error TYPE "${observations}" cases ${index} ${field}) |
| 43 | + if(NOT error STREQUAL "NOTFOUND" OR NOT field_type STREQUAL "STRING") |
| 44 | + message(FATAL_ERROR "Native validator textual metadata must be strings") |
| 45 | + endif() |
| 46 | + endforeach() |
| 47 | + string(JSON name GET "${observations}" cases ${index} name) |
| 48 | + string(JSON actual_context GET "${observations}" cases ${index} context) |
| 49 | + string(JSON validator GET "${observations}" cases ${index} validator) |
| 50 | + if(NOT name STREQUAL "${key}-${context}" OR NOT actual_context STREQUAL context OR |
| 51 | + NOT validator MATCHES "^mustBe[A-Za-z]+$") |
| 52 | + message(FATAL_ERROR "Native validator order/identity differs at ${index}") |
| 53 | + endif() |
| 54 | + string(JSON success_type TYPE "${observations}" cases ${index} succeeded) |
| 55 | + string(JSON success GET "${observations}" cases ${index} succeeded) |
| 56 | + string(JSON identifier GET "${observations}" cases ${index} exceptionIdentifier) |
| 57 | + string(JSON exception_message GET "${observations}" cases ${index} exceptionMessage) |
| 58 | + string(JSON cause_type TYPE "${observations}" cases ${index} causeIdentifiers) |
| 59 | + if(NOT success_type STREQUAL "BOOLEAN" OR NOT cause_type STREQUAL "ARRAY") |
| 60 | + message(FATAL_ERROR "Native validator outcome/cause metadata has invalid types") |
| 61 | + endif() |
| 62 | + if(success) |
| 63 | + if(NOT identifier STREQUAL "" OR NOT exception_message STREQUAL "") |
| 64 | + message(FATAL_ERROR "Successful native validator observation retains an exception") |
| 65 | + endif() |
| 66 | + elseif(NOT identifier MATCHES "^MATLAB:[A-Za-z0-9_:]+$" OR exception_message STREQUAL "") |
| 67 | + message(FATAL_ERROR "Failed native validator observation has no complete native exception") |
| 68 | + endif() |
| 69 | + math(EXPR index "${index} + 1") |
| 70 | + endforeach() |
| 71 | + endforeach() |
| 72 | + message(STATUS "Checked ${count} native validator observations; target parity is verified separately") |
| 73 | +endfunction() |
0 commit comments