feat(validate): 2.1 errors for the glossary registries

Validation now checks what 2.1 adds: registry ids carry their prefix and
are unique across all registries (E2101); a target's terms, equations,
values, and misconceptions name declared entries (E2102); equation
symbols resolve (E2103); values give a value or an ordered range and a
declared term (E2104); citation keys in the new registries resolve
(E2105); brace references in student-facing prose resolve (E2106);
`conflicts` and `target_text_forbid` patterns compile (E2107); and a bank
option's misconception_id is declared (E2108).

An unresolved {lo-...} or {t-...} in a field 2.0 already had (objective
and target text, reading notes) is left to the linter, because 2.0
accepted it and rendered it literally; the new reference kinds and the
new fields are checked everywhere.

Adds the `regex` crate, with default features off, for the course's own
patterns. Each error has a test built from the prototype's self-test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
alexmandClaude committed 2026-11-16 11:58:53 -05:00
1 parent 51a2fd235f
commit 960cf6cbd3
7 files changed
+915 -36

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: Prosperity-3.0.0
// Copyright Scienting
// Source: https://git.scient.ing/education/coursebank
//! Fixtures shared by the 2.1 integration tests: the examples in
//! `docs/design/2.1/examples/`, copied into a scratch directory so a test may
//! change them.
#![allow(dead_code)]
use std::path::{Path, PathBuf};
/// `docs/design/2.1/`.
pub fn design() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("docs/design/2.1")
}
/// A fresh, empty directory under the system temp dir.
pub fn scratch(tag: &str) -> PathBuf {
let dir = std::env::temp_dir().join(format!("coursebank-2-1-{tag}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
dir
}
/// Copies a directory tree.
pub fn copy_tree(from: &Path, to: &Path) {
std::fs::create_dir_all(to).unwrap();
for entry in std::fs::read_dir(from).unwrap() {
let path = entry.unwrap().path();
let target = to.join(path.file_name().unwrap());
if path.is_dir() {
copy_tree(&path, &target);
} else {
std::fs::copy(&path, &target).unwrap();
}
}
}
/// The 2.1 example course, copied so a test may change it.
pub fn v21_course(tag: &str) -> PathBuf {
let root = scratch(tag);
copy_tree(&design().join("examples/v21"), &root);
let _ = std::fs::remove_file(root.join("lecture-page-preview.md"));
root
}
/// Replaces the first occurrence of `from` with `to` in a file of a course.
pub fn edit(root: &Path, relative: &str, from: &str, to: &str) {
let path = root.join(relative);
let text = std::fs::read_to_string(&path).unwrap();
assert!(text.contains(from), "{relative} does not contain {from:?}");
std::fs::write(&path, text.replacen(from, to, 1)).unwrap();
}