The registry's unregistered labels now hold every wai.quantum string the tree uses that no revision registers, each saying what it names, grouped: the receipt kinds, the modules of wai-quantum, the names a record's members carry, the fabric's kernels and corpora, the circuit contracts' revisions, the documents with no schema file, the digest domains, and the strings the tests and the provider corpus give a reader to see it refuse them. A document's name, wai.quantum.<document>/<major>, is accounted for by its schema file (schemas/<document>.v<major>.json, its title the name) and needs no row. scripts/check-wai-quantum-names.py reads the registry export and the schema files and every text file but the changelog, and names the file and line of any string neither accounts for; it also fails on a pattern that matches nothing, a schema file whose title is not its file's name, a quantum label nothing outside the registry uses, and a string held twice. The repository checks run it and its self-test. The wai-quantum constants test compares the receipt kinds alone, and the registry test refuses a label listed twice. Co-Authored-By: Claude Opus 5.5 <[email protected]>
115 lines
5.2 KiB
Shell
Executable file
115 lines
5.2 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# check-wai-quantum-names-selftest.sh — check-wai-quantum-names.py can fail.
|
|
#
|
|
# A check that cannot fail is decoration. This builds a scratch repository shaped like
|
|
# this one (a registry export, the registry's table and page, a crate with a schema file
|
|
# and a source that uses each kind of accounted string, a changelog, a binary file) and
|
|
# asserts that the check passes it, and fails each way a string can go unaccounted,
|
|
# naming the file and line. The namespace's prefix is spelled through $q here, so this
|
|
# file holds none of the test's strings itself.
|
|
set -uo pipefail
|
|
|
|
here=$(cd "$(dirname "$0")" && pwd)
|
|
check="$here/check-wai-quantum-names.py"
|
|
tmp=$(mktemp -d)
|
|
trap 'rm -rf "$tmp"' EXIT
|
|
q=wai.quantum
|
|
|
|
mk() {
|
|
rm -rf "$tmp/repo"
|
|
mkdir -p "$tmp/repo/wai/registry" "$tmp/repo/wai/wai-rs/src/codecs" "$tmp/repo/wai/crate/src" \
|
|
"$tmp/repo/wai/crate/schemas" "$tmp/repo/wai/changes"
|
|
cd "$tmp/repo" || exit 2
|
|
git init -q .
|
|
cat > wai/registry/capabilities.json <<J
|
|
{"schema": "x",
|
|
"capabilities": [{"capability": "$q.circuit"}, {"capability": "wai.video.av1"}],
|
|
"identifiers": [{"identifier": "wai.det.fixed64"}],
|
|
"unregistered_labels": [{"label": "$q.module", "reason": "a module label"},
|
|
{"label": "$q.fam.one", "reason": "a module label"}],
|
|
"wire_identifiers": [{"name": "$q.wire/1", "kind": "document-kind"}]}
|
|
J
|
|
cat > wai/wai-rs/src/codecs/registry.rs <<R
|
|
label("$q.module", "a module label"),
|
|
label("$q.fam.one", "a module label"),
|
|
R
|
|
printf '| \x60%s\x60 | a module label |\n' "$q.module" "$q.fam.one" > wai/REGISTRY.md
|
|
cat > wai/crate/schemas/doc.v1.json <<J
|
|
{"title": "$q.doc/1", "properties": {"inner": {"properties": {"format": {"const": "$q.inner/1"}}}}}
|
|
J
|
|
cat > wai/crate/src/lib.rs <<R
|
|
//! The circuit core: \`$q.circuit\`, the module \`$q.module\` and the family \`$q.fam.*\`.
|
|
pub const DOC: &str = "$q.doc/1";
|
|
pub const INNER: &str = "$q.inner/1";
|
|
pub const WIRE: &str = "$q.wire/1";
|
|
pub const FAM: &str = "$q.fam.one";
|
|
// A placeholder and a prefix are not strings: $q.<document>, "$q.".
|
|
pub fn sentence() -> &'static str { "it reads $q.circuit." }
|
|
R
|
|
# The changelog keeps names as they were, and a binary file is not a source.
|
|
printf '### A change\n\n- \x60%s\x60 was renamed.\n' "$q.renamed" > wai/CHANGELOG.md
|
|
printf '### A change\n\n- \x60%s\x60 is new.\n' "$q.entry" > wai/changes/2026-01-01-a-change.md
|
|
printf 'WQC1\0\0%s\0' "$q.circuit/9" > wai/crate/vector.bin
|
|
git add -A
|
|
cd "$here" || exit 2
|
|
}
|
|
|
|
fails=0
|
|
expect() { # expect <pass|fail> <what> [text the output must hold]
|
|
local want=$1 what=$2 needle=${3:-} out rc
|
|
out=$(python3 -I "$check" --root "$tmp/repo" 2>&1); rc=$?
|
|
if [ "$want" = pass ] && [ $rc -ne 0 ]; then echo "FAIL $what: the check failed"; printf '%s\n' "$out" | sed 's/^/ /'; fails=$((fails+1)); return; fi
|
|
if [ "$want" = fail ] && [ $rc -eq 0 ]; then echo "FAIL $what: the check passed"; printf '%s\n' "$out" | sed 's/^/ /'; fails=$((fails+1)); return; fi
|
|
if [ -n "$needle" ] && ! printf '%s\n' "$out" | grep -qF -- "$needle"; then
|
|
echo "FAIL $what: the output does not say '$needle'"; printf '%s\n' "$out" | sed 's/^/ /'; fails=$((fails+1)); return
|
|
fi
|
|
echo "ok $what"
|
|
}
|
|
|
|
mk
|
|
expect pass "every kind of accounted string, a placeholder, a prefix, the changelog and a binary file"
|
|
|
|
mk
|
|
printf 'pub const X: &str = "%s";\n' "$q.planted" >> "$tmp/repo/wai/crate/src/lib.rs"
|
|
expect fail "an unlisted string in a tracked source" "wai/crate/src/lib.rs:8: $q.planted is not registered"
|
|
|
|
mk
|
|
printf '%s\n' "see $q.planted/1" > "$tmp/repo/wai/crate/notes.md"
|
|
expect fail "an unlisted string in a file not yet added" "wai/crate/notes.md:1: $q.planted/1"
|
|
|
|
mk
|
|
printf '%s\n' "the family $q.nofam.*" >> "$tmp/repo/wai/crate/src/lib.rs"
|
|
expect fail "a pattern that matches nothing" "$q.nofam.* matches no"
|
|
|
|
mk
|
|
sed -i.bak "s|$q.doc/1\"|$q.doc/2\"|" "$tmp/repo/wai/crate/schemas/doc.v1.json" && rm "$tmp/repo/wai/crate/schemas/doc.v1.json.bak"
|
|
expect fail "a schema whose title is not its file's name" "doc.v1.json: its title is $q.doc/2"
|
|
|
|
mk
|
|
sed -i.bak "/FAM/d" "$tmp/repo/wai/crate/src/lib.rs" && rm "$tmp/repo/wai/crate/src/lib.rs.bak"
|
|
sed -i.bak "s|$q.fam.\*|the family|" "$tmp/repo/wai/crate/src/lib.rs" && rm "$tmp/repo/wai/crate/src/lib.rs.bak"
|
|
expect fail "a label nothing outside the registry uses" "the label $q.fam.one is used nowhere outside"
|
|
|
|
mk
|
|
sed -i.bak "s|\"name\": \"$q.wire/1\"|\"name\": \"$q.module\"|" "$tmp/repo/wai/registry/capabilities.json" && rm "$tmp/repo/wai/registry/capabilities.json.bak"
|
|
expect fail "a string the registry holds twice" "$q.module is held twice"
|
|
|
|
mk
|
|
printf 'pub const X: &str = "%s";\n' "$q.planted" >> "$tmp/repo/wai/crate/src/lib.rs"
|
|
sed -i.bak "s|{\"label\": \"$q.module\"|{\"label\": \"$q.planted\", \"reason\": \"r\"}, &|" "$tmp/repo/wai/registry/capabilities.json" && rm "$tmp/repo/wai/registry/capabilities.json.bak"
|
|
expect pass "the planted string, once listed as a label"
|
|
|
|
mk
|
|
rm "$tmp/repo/wai/registry/capabilities.json"
|
|
expect fail "no registry export (fails closed)" "cannot read wai/registry/capabilities.json"
|
|
|
|
mk
|
|
rm -rf "$tmp/repo/.git"
|
|
expect fail "not a git checkout (fails closed)" "check-wai-quantum-names: git"
|
|
|
|
if [ $fails -ne 0 ]; then
|
|
echo "$fails self-test case(s) failed"
|
|
exit 1
|
|
fi
|
|
echo "check-wai-quantum-names: every self-test case behaves"
|