|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Meta-test for the QC SPARQL violation queries (berkeleybop/metpo#500). |
| 3 | +# |
| 4 | +# Runs every src/sparql/*-violation.sparql against the positive-control fixture |
| 5 | +# (qc-positive-fixture.ttl) and asserts each returns >= 1 row. This proves the |
| 6 | +# checks actually MATCH METPO terms: four of them filter on the term namespace |
| 7 | +# with STRSTARTS(str(?term), "https://w3id.org/metpo/"), and that filter was |
| 8 | +# once "https://w3id.org/METPO_", matching nothing, so every check silently |
| 9 | +# reported "0 violations" (#487, #465). A check that cannot fail is worse than |
| 10 | +# no check. |
| 11 | +# |
| 12 | +# This harness lives OUTSIDE the ODK-managed tree (src/ontology, src/sparql): it |
| 13 | +# only READS the queries under src/sparql. Queries are discovered dynamically, |
| 14 | +# so a new *-violation.sparql with no seeded fixture case fails here, which |
| 15 | +# forces the fixture to stay complete. |
| 16 | +# |
| 17 | +# Run locally from src/ontology: |
| 18 | +# sh run.sh bash ../../tests/sparql_qc/run_sparql_metatest.sh |
| 19 | +# Requires: robot on PATH (present in the obolibrary/odkfull container). |
| 20 | +set -euo pipefail |
| 21 | + |
| 22 | +HERE="$(cd "$(dirname "$0")" && pwd)" |
| 23 | +REPO_ROOT="$(cd "$HERE/../.." && pwd)" |
| 24 | +SPARQLDIR="$REPO_ROOT/src/sparql" |
| 25 | +FIXTURE="$HERE/qc-positive-fixture.ttl" |
| 26 | +OUT="$(mktemp -d)" |
| 27 | +trap 'rm -rf "$OUT"' EXIT |
| 28 | + |
| 29 | +shopt -s nullglob |
| 30 | +queries=("$SPARQLDIR"/*-violation.sparql) |
| 31 | +if [ "${#queries[@]}" -eq 0 ]; then |
| 32 | + echo "::error::no *-violation.sparql queries found in $SPARQLDIR" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +fail=0 |
| 37 | +for q in "${queries[@]}"; do |
| 38 | + name="$(basename "$q")" |
| 39 | + res="$OUT/$name.tsv" |
| 40 | + robot query --input "$FIXTURE" --query "$q" "$res" |
| 41 | + rows=$(($(wc -l < "$res") - 1)) # the first line is the SELECT header |
| 42 | + if [ "$rows" -ge 1 ]; then |
| 43 | + echo "OK $name matched $rows fixture violation(s)" |
| 44 | + else |
| 45 | + echo "::error::$name matched 0 rows against the positive-control fixture: the check is a silent no-op (e.g. wrong term-namespace filter)." |
| 46 | + fail=1 |
| 47 | + fi |
| 48 | +done |
| 49 | + |
| 50 | +if [ "$fail" -ne 0 ]; then |
| 51 | + echo |
| 52 | + echo "One or more QC violation queries matched nothing they are meant to catch." |
| 53 | + echo "Fix: seed the missing case in tests/sparql_qc/qc-positive-fixture.ttl, or" |
| 54 | + echo "correct the query's term-namespace filter (https://w3id.org/metpo/)." |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | + |
| 58 | +echo "All ${#queries[@]} QC violation queries matched their positive-control fixture." |
| 59 | + |
| 60 | +# --------------------------------------------------------------------------- |
| 61 | +# Ontology-header QC (berkeleybop/metpo#502). This check is maintained here, |
| 62 | +# outside the ODK tree, rather than as an edit to an ODK query. It must: |
| 63 | +# (a) match >= 1 row against the bad-header fixture (proven able to fail), and |
| 64 | +# (b) match 0 rows against the real released metpo.owl (the actual assertion). |
| 65 | +# --------------------------------------------------------------------------- |
| 66 | +echo |
| 67 | +HEADER_Q="$HERE/ontology-header-check.sparql" |
| 68 | +REAL_OWL="$REPO_ROOT/metpo.owl" |
| 69 | + |
| 70 | +robot query --input "$FIXTURE" --query "$HEADER_Q" "$OUT/header-fixture.tsv" |
| 71 | +hrows=$(($(wc -l < "$OUT/header-fixture.tsv") - 1)) |
| 72 | +if [ "$hrows" -ge 1 ]; then |
| 73 | + echo "OK ontology-header-check.sparql matched $hrows fixture violation(s)" |
| 74 | +else |
| 75 | + echo "::error::ontology-header-check.sparql matched 0 rows against the fixture: the check is a silent no-op." |
| 76 | + fail=1 |
| 77 | +fi |
| 78 | + |
| 79 | +if [ -f "$REAL_OWL" ]; then |
| 80 | + robot query --input "$REAL_OWL" --query "$HEADER_Q" "$OUT/header-real.tsv" |
| 81 | + rrows=$(($(wc -l < "$OUT/header-real.tsv") - 1)) |
| 82 | + if [ "$rrows" -le 0 ]; then |
| 83 | + echo "OK ontology-header-check.sparql found no problems in metpo.owl" |
| 84 | + else |
| 85 | + echo "::error::the ontology header in metpo.owl has $rrows metadata problem(s):" |
| 86 | + cat "$OUT/header-real.tsv" |
| 87 | + fail=1 |
| 88 | + fi |
| 89 | +else |
| 90 | + echo "::error::expected released ontology at $REAL_OWL but it is missing." |
| 91 | + fail=1 |
| 92 | +fi |
| 93 | + |
| 94 | +if [ "$fail" -ne 0 ]; then |
| 95 | + exit 1 |
| 96 | +fi |
0 commit comments