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

+4 -36
View File
@@ -9,40 +9,16 @@
//! `examples/v21/` uses every new field, and `schemas/` is the JSON Schema each
//! generated file must equal.
use std::path::{Path, PathBuf};
mod common;
use std::path::PathBuf;
use common::{design, scratch, v21_course};
use coursebank::catalog::Catalog;
use coursebank::course::CourseFile;
use coursebank::jsonschema::{self, Kind};
use serde_json::Value;
/// `docs/design/2.1/`.
fn design() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("docs/design/2.1")
}
/// A fresh, empty directory under the system temp dir.
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.
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 JSON pointers at which two values differ.
fn differences(path: &str, generated: &Value, target: &Value, out: &mut Vec<String>) {
match (generated, target) {
@@ -166,14 +142,6 @@ fn the_2_0_fragments_load_and_validate_unchanged() {
assert!(course.terms.is_empty() && course.equations.is_empty());
}
/// 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
}
#[test]
fn the_2_1_example_loads_every_new_field() {
let root = v21_course("v21-load");