#!/usr/bin/env bash # # check-wai-corpus-licences-selftest.sh — check-wai-corpus-licences.py can fail. # # A check that cannot fail is decoration. This builds a scratch tree shaped like the # repository (wai/neural-conformance with vector directories, its two hash manifests and # licences.json, wai/tensor-conformance with one vector and its licences.json, and a # generator below wai/) whose every vector has a licence record, and # asserts that the check passes it, and fails each way a record can be missing, name a # licence that does not permit redistribution, or leave out what its content needs. # Nothing here reads the real tree, and nothing needs a network. set -uo pipefail here=$(cd "$(dirname "$0")" && pwd) check="$here/check-wai-corpus-licences.py" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT fails=0 # mk : a corpus that holds. `seeded` and `trained` are generated, `third` is a # third-party picture under CC-BY-4.0; `trained` is marked trained in expected_hashes.json. mk() { local c="$1/wai/neural-conformance" mkdir -p "$c/vectors/seeded" "$c/vectors/trained" "$c/vectors/third" "$1/wai/tools" printf '# a generator\n' > "$1/wai/tools/gen.py" cat > "$c/expected_hashes.json" <<'J' {"seeded": {"rgb_hash": "00"}, "trained": {"trained": true, "rgb_hash": "01"}, "third": {"rgb_hash": "02"}} J cat > "$c/sha256.json" <<'J' {"seeded": {"sha256": "00"}, "trained": {"sha256": "01"}, "third": {"sha256": "02"}} J cat > "$c/licences.json" <<'J' {"format": "wai-corpus-licences/1", "vectors": { "seeded": {"licence": "Apache-2.0", "content": "generated", "generator": "tools/gen.py", "input": "seed 1"}, "trained": {"licence": "Apache-2.0", "content": "generated", "generator": "tools/gen.py", "input": "seed 2, stream 0", "training": {"content": "generated", "generator": "tools/gen.py", "input": "seed 2, streams 1 to 8"}}, "third": {"licence": "CC-BY-4.0", "content": "third-party", "source": "a picture and its licence page", "generator": "tools/gen.py"} }} J # The check reads every corpus in its CORPORA, so the tree holds each of them. local t="$1/wai/tensor-conformance" mkdir -p "$t/vectors/frame" cat > "$t/licences.json" <<'J' {"format": "wai-corpus-licences/1", "vectors": { "frame": {"licence": "Apache-2.0", "content": "generated", "generator": "tools/gen.py", "input": "seed 3"} }} J } # edit edit() { python3 -I - "$1/wai/neural-conformance/licences.json" "$2" <<'P' import json, sys p, stmt = sys.argv[1], sys.argv[2] d = json.load(open(p)) v = d["vectors"] exec(stmt) json.dump(d, open(p, "w")) P } want() { # want