Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

2.5 KB
Raw Blame
#!/usr/bin/env sh
#
# Emit theories/FixtureData.v from the committed Horn fixtures.
#
# The point of generating rather than transcribing is that the kernel then checks the REAL
# bytes. A hand-typed copy of a fixture is a second file that can drift from the first, and
# a gate over a drifted copy is a gate over nothing. The generated file is not committed:
# build.sh runs this before every build, so there is no window in which checked-in data and
# checked-in fixtures can disagree, because there is no checked-in data.
#
# POSIX sh and sed, and nothing else. This used to be a Python script, which was fine on a
# developer machine and a hazard in CI: the only way to get Rocq 9.2 on a runner is the
# official container image, and whether that image carries a python3 is not something this
# repository controls. sed is in every image that can build anything.
#
# Rocq string literals take a newline and a tab literally and escape a double quote by
# doubling it. Nothing else needs escaping, and Rocq reads the file byte by byte into
# `string`.
set -eu

here=$(cd "$(dirname "$0")" && pwd)
fix="$here/../tests/fixtures/horn"
out="$here/theories/FixtureData.v"

# name:path pairs, relative to tests/fixtures/horn/
files="
f_builtin_rules:builtin_rules.tsv
f_short_rules:short_rules.tsv
f_user_rules:user_rules.tsv
f_asserted:asserted.tsv
f_good:good.tsv
f_bad_binding:bad_binding.tsv
f_bad_conclusion:bad_conclusion.tsv
f_bad_index:bad_index.tsv
f_bad_premise:bad_premise.tsv
f_bad_self:bad_self.tsv
f_deep_mutual_asserted:deep/mutual_asserted.tsv
f_deep_mutual_cert:deep/mutual_cert.tsv
f_deep_mutual_seeded_asserted:deep/mutual_seeded_asserted.tsv
f_deep_self_support_asserted:deep/self_support_asserted.tsv
f_deep_self_support_cert:deep/self_support_cert.tsv
"

n=0
{
  cat <<'HEADER'
(** * The committed fixture bytes, as Rocq strings.

    GENERATED by [rocq/gen_fixture_data.sh] from [tests/fixtures/horn/]. Do not edit and
    do not commit: [rocq/build.sh] regenerates it before every build, so the kernel always
    evaluates the bytes that are in the tree rather than a copy of them that was once in
    the tree. *)

From Stdlib Require Import String.
Open Scope string_scope.
HEADER

  for pair in $files; do
    name=${pair%%:*}
    rel=${pair#*:}
    if [ ! -f "$fix/$rel" ]; then
      echo "missing fixture: $fix/$rel" >&2
      exit 1
    fi
    printf '\n(** [tests/fixtures/horn/%s] *)\nDefinition %s : string :=\n"' "$rel" "$name"
    sed 's/"/""/g' "$fix/$rel"
    printf '".\n'
    n=$((n + 1))
  done
} > "$out"

echo "wrote $out from $n fixtures" >&2