Files
betterxen/scripts/audit/claims.sh
izdat-sl4w d01627b3de audit: read and write tracked files as UTF-8
The generated-status check and the claims audit called
Path.read_text()/write_text() without encoding=, so they used the process
locale encoding. Under an ASCII locale the status check raises
UnicodeDecodeError on docs/claims.toml, and under cp1252 it reports a
spurious xenora-progress.svg difference, so a current tree fails the
documented checkout command. Both scripts now pass encoding="utf-8", as
the rest of scripts/ does, and CI runs the two checks again under a
non-UTF-8 locale so the requirement stays enforced.

Closes #334

Signed-off-by: izdat-sl4w <76667566+izdat-sl4w@users.noreply.github.com>
2026-11-24 18:09:21 +01:00

61 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
set -eu
cd "$(dirname "$0")/../.."
exec python3 - <<'PY'
from collections import Counter
from pathlib import Path
import re
import sys
import tomllib
registry = Path("docs/claims.toml")
claims = tomllib.loads(registry.read_text(encoding="utf-8"))["claim"]
classes = {}
errors = []
claim_id = re.compile(r"\bCLAIM-[A-Z0-9]+(?:-[A-Z0-9]+)*\b")
for entry in claims:
identifier = entry.get("id", "")
evidence = entry.get("class")
if not claim_id.fullmatch(identifier) or identifier in classes:
errors.append(f"invalid or duplicate claim ID {identifier!r}")
classes[identifier] = evidence
if evidence not in {"A", "B", "C", "D", "E", "F", "U"}:
errors.append(f"{identifier}: invalid evidence class")
sources = entry.get("sources")
if not isinstance(sources, list) or not sources or not all(
isinstance(source, str) and source.strip() for source in sources
):
errors.append(f"{identifier}: expected one or more sources")
for field in ("claim", "architecture", "retrieved", "test", "uncertainty"):
if not str(entry.get(field, "")).strip():
errors.append(f"{identifier}: missing {field}")
files = [Path("README.md"), Path("AGENTS.md"), *Path("docs").rglob("*"),
*Path("crates").rglob("*.rs")]
for source in files:
if source == registry or source.suffix not in {".md", ".toml", ".rs"}:
continue
for reference in set(claim_id.findall(source.read_text(encoding="utf-8"))) - classes.keys():
errors.append(f"{source}: unregistered {reference}")
status = tomllib.loads(Path("docs/status.toml").read_text(encoding="utf-8"))
for feature in status["feature"]:
verification = feature.get("hardware_verification", "")
if verification.casefold() != "verified":
continue
references = feature.get("claims", [])
evidence = {classes.get(reference) for reference in references}
if not references or not evidence <= {"A", "B"} or "A" not in evidence:
errors.append(f"{feature['id']}: verified hardware needs class A evidence")
if not feature.get("test") or not feature.get("correctness", "").endswith("passed"):
errors.append(f"{feature['id']}: verified hardware needs a recorded passing test")
if errors:
sys.exit("\n".join(sorted(errors)))
counts = Counter(classes.values())
print(f"Checked {len(classes)} claims ({', '.join(f'{k}={v}' for k, v in sorted(counts.items()))}).")
PY