feat: splitting

This commit is contained in:
alexm committed 2026-09-26 01:15:12 -04:00
1 parent 220363d4d3
commit eabc98ad31
29 files changed
+4843 -234

No files matched your search

+44 -1
View File
@@ -145,8 +145,16 @@ pub struct SealedItem {
/// The item's global id.
pub item: String,
/// The item version as administered.
/// Retained only so a pre-2.0 seal still loads. Ignored when reasoning
/// about the item, but still written: [`SealFile::digest_input`] covers it,
/// so dropping it on a round trip would invalidate the digest of every
/// administration sealed before 2.0.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub version: Option<u32>,
/// The stem's digest as administered.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub stem_digest: Option<String>,
/// The item's content fingerprint, the same one
/// [`crate::item::Item::fingerprint`] computes, so a seal and a bank can be
/// compared without re-hashing either by hand.
@@ -484,7 +492,8 @@ fn sealed_item(
SealedItem {
number: placement.number,
item: placement.item.clone(),
version: placement.version.or(Some(item.version)),
version: None,
stem_digest: Some(item.stem_digest()),
fingerprint: item.fingerprint(),
points: placement
.points
@@ -638,6 +647,33 @@ impl SealFile {
yaml::read(path)
}
/// Loads every seal in a directory, oldest administration first.
///
/// # Arguments
///
/// * `dir` - the seals directory.
///
/// # Returns
///
/// The seals, empty when the directory does not exist.
///
/// # Errors
///
/// Propagates load failures, including a seal that does not parse.
pub fn load_all(dir: &Path) -> Result<Vec<SealFile>> {
let mut out = Vec::new();
for path in crate::yaml::list_yaml(dir)? {
out.push(SealFile::load(&path)?);
}
out.sort_by(|a, b| {
a.seal
.date
.cmp(&b.seal.date)
.then(a.seal.assessment.cmp(&b.seal.assessment))
});
Ok(out)
}
/// Loads the seal for an assessment, if one has been written.
///
/// Absence is not an error. A course that has never sealed anything should
@@ -719,6 +755,12 @@ impl SealFile {
self.schema_version, self.seal.assessment, self.seal.course, self.seal.term
));
for item in &self.items {
// Appended only when present: a seal written before 2.0 has to keep
// producing the input it was digested from, or every older
// administration fails verification.
if let Some(stem) = &item.stem_digest {
buf.push_str(&format!("stem\u{1f}{}\u{1f}{stem}\n", item.number));
}
buf.push_str(&format!(
"item\u{1f}{}\u{1f}{}\u{1f}{}\u{1f}{}\u{1f}{}\u{1f}{}\u{1f}{}\u{1f}{}\u{1f}",
item.number,
@@ -1157,6 +1199,7 @@ mod tests {
number: 1,
item: "b::q-1".into(),
version: Some(1),
stem_digest: None,
fingerprint: "abc".into(),
points: 1.0,
bonus: false,