feat(checker): cph-model manifest v2 — Artifact-with-fields + typed steps (WU-B', ADR-0011)

[targets.*] reworked: artifact is now an inline table with a type discriminator
({type="single-file",filepath} / {type="file-tree",root,outputs}) and steps is an
ordered array-of-tables ({type="typst-compile",template} / {type="shell",run}).
numbering removed entirely (presentation lives in the template per ADR-0011).

TargetConfig { name, artifact: Artifact, steps: Vec<Step> }; Artifact and Step
mirror Spec.Courseware.Artifact / Spec.Courseware.Step (doc-cited). Sensible
defaults so a bare [targets.student] still works: single-file build/<name>.pdf +
one typst-compile exports/<name>.typ. Malformed artifact/step type → non-fatal
SchemaViolation with fallback. 8 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-22 09:57:50 +08:00
parent de87cddaf1
commit d5bce1bede
4 changed files with 473 additions and 190 deletions
+86 -38
View File
@@ -48,10 +48,21 @@ fn valid_two_part_lesson_loads_in_order_with_no_errors() {
// Targets are collected from [targets.*], in declared order.
assert_eq!(lesson.target_names(), vec!["student", "teacher"]);
// Empty `[targets.x]` bodies → all-default build config, no diagnostics.
// Empty `[targets.x]` bodies → all-default build config, no diagnostics:
// single-file artifact at build/<name>.pdf + one typst-compile step.
for target in &lesson.targets {
assert_eq!(target.artifact, cph_model::ArtifactKind::SingleFile);
assert_eq!(target.numbering, None);
assert_eq!(
target.artifact,
cph_model::Artifact::SingleFile {
filepath: PathBuf::from(format!("build/{}.pdf", target.name)),
}
);
assert_eq!(
target.steps,
vec![cph_model::Step::TypstCompile {
template: PathBuf::from(format!("exports/{}.typ", target.name)),
}]
);
}
// Descriptor dir is absolute, anchored under the root.
@@ -129,7 +140,7 @@ fn missing_manifest_is_a_hard_failure() {
#[test]
fn structured_target_configs_parse_into_typed_builds() {
use cph_model::ArtifactKind;
use cph_model::{Artifact, Step};
let (lesson, diags) = load(&fixture("target-configs"));
let lesson = lesson.expect("target-configs fixture must produce a Lesson");
@@ -141,41 +152,66 @@ fn structured_target_configs_parse_into_typed_builds() {
// Declared order is preserved.
assert_eq!(lesson.target_names(), vec!["student", "archive", "teacher"]);
// student: explicit single-file + heading numbering override, in order.
// student: explicit single-file artifact (with filepath) + one
// typst-compile step (with template).
let student = &lesson.targets[0];
assert_eq!(student.name, "student");
assert_eq!(student.artifact, ArtifactKind::SingleFile);
let numbering = student
.numbering
.as_ref()
.expect("student declares a numbering override");
assert_eq!(
numbering.heading.as_deref(),
Some(
&[
"{1:一}、".to_string(),
"{1:1}.{2:1}".to_string(),
"{1:1}.{2:1}.{3:1}".to_string(),
][..]
)
student.artifact,
Artifact::SingleFile {
filepath: PathBuf::from("build/student.pdf"),
}
);
assert_eq!(
student.steps,
vec![Step::TypstCompile {
template: PathBuf::from("exports/student.typ"),
}]
);
// archive: file-tree artifact, no presentation override.
// archive: file-tree artifact (root + outputs glob) + two ordered steps,
// a typst-compile followed by a shell step (order preserved).
let archive = &lesson.targets[1];
assert_eq!(archive.name, "archive");
assert_eq!(archive.artifact, ArtifactKind::FileTree);
assert_eq!(archive.numbering, None);
assert_eq!(
archive.artifact,
Artifact::FileTree {
root: PathBuf::from("build/archive"),
outputs: "**/*.{html,js,json}".to_string(),
}
);
assert_eq!(
archive.steps,
vec![
Step::TypstCompile {
template: PathBuf::from("exports/archive.typ"),
},
Step::Shell {
run: "npm run build".to_string(),
},
]
);
// teacher: empty body → all defaults, numbering absent.
// teacher: empty body → all defaults.
let teacher = &lesson.targets[2];
assert_eq!(teacher.name, "teacher");
assert_eq!(teacher.artifact, ArtifactKind::SingleFile);
assert_eq!(teacher.numbering, None);
assert_eq!(
teacher.artifact,
Artifact::SingleFile {
filepath: PathBuf::from("build/teacher.pdf"),
}
);
assert_eq!(
teacher.steps,
vec![Step::TypstCompile {
template: PathBuf::from("exports/teacher.typ"),
}]
);
}
#[test]
fn malformed_target_config_is_non_fatal_with_schema_violations() {
use cph_model::ArtifactKind;
use cph_model::{Artifact, Step};
let (lesson, diags) = load(&fixture("bad-target-config"));
let lesson = lesson.expect("bad-target-config must still produce a Lesson");
@@ -183,19 +219,31 @@ fn malformed_target_config_is_non_fatal_with_schema_violations() {
// Both targets survive despite their malformed fields.
assert_eq!(lesson.target_names(), vec!["student", "teacher"]);
// Bad `artifact` value → SchemaViolation, target kept with default artifact.
// Bad `artifact.type` → SchemaViolation, target kept with default artifact.
let student = &lesson.targets[0];
assert_eq!(student.artifact, ArtifactKind::SingleFile);
assert_eq!(
student.artifact,
Artifact::SingleFile {
filepath: PathBuf::from("build/student.pdf"),
}
);
// Bad `numbering.heading` (not an array of strings) → heading stays None,
// but the numbering table itself is present.
// Bad step `type` → the step is skipped; the file-tree artifact survives and
// the empty step list falls back to the default step.
let teacher = &lesson.targets[1];
assert_eq!(teacher.artifact, ArtifactKind::FileTree);
let teacher_numbering = teacher
.numbering
.as_ref()
.expect("teacher declares a numbering table");
assert_eq!(teacher_numbering.heading, None);
assert_eq!(
teacher.artifact,
Artifact::FileTree {
root: PathBuf::from("build/teacher"),
outputs: "**/*.html".to_string(),
}
);
assert_eq!(
teacher.steps,
vec![Step::TypstCompile {
template: PathBuf::from("exports/teacher.typ"),
}]
);
let violations: Vec<_> = diags
.iter()
@@ -208,12 +256,12 @@ fn malformed_target_config_is_non_fatal_with_schema_violations() {
);
assert!(
violations.iter().any(|d| d.message.contains("pdf-thing")),
"a diagnostic should name the bad artifact value, got: {diags:?}"
"a diagnostic should name the bad artifact type, got: {diags:?}"
);
assert!(
violations
.iter()
.any(|d| d.message.contains("numbering.heading")),
"a diagnostic should name the malformed numbering.heading, got: {diags:?}"
.any(|d| d.message.contains("make-it-nice")),
"a diagnostic should name the bad step type, got: {diags:?}"
);
}