Skip to content

Commit a6d8358

Browse files
feat(schema): bump schemars to 1.x; round-trip + Draft-2020-12 tests (#5)
Chunk M1-W1-C of M1 plan — closes Plan §6.1. Workspace dep: - schemars 0.8 → 1 (latest 1.2.1; MSRV 1.74 stays well below our 1.85 pin). 1.x emits Draft 2020-12 by default; the existing JsonSchema derives compile unchanged. pearlite-schema dev-dep: - serde_json (workspace dep, used only in tests). Two acceptance tests in lib.rs::cross_cutting_tests: - schemars_output_is_draft_2020_12 — generates the JSON Schema for DeclaredState and asserts the $schema field claims Draft 2020-12. This is the Plan §6.1 "schema: schemars_output_is_2020_12" gate. - declared_state_round_trips_through_toml — parses host_full.toml, serializes it back, re-parses, and asserts equality. This is the "round-trip: declared_state_serde — every field round-trips through TOML" gate. Plan §6.1 "Done when" status now: - Public types derive Serialize, Deserialize, JsonSchema, Debug, Clone (+Eq/PartialEq/Hash/Default where applicable). ✓ - cargo doc --no-deps emits zero "missing docs" warnings. ✓ - A representative resolved.toml fixture round-trips without loss. ✓ - schemars output validates as Draft 2020-12. ✓ - Zero unwrap()/expect()/panic! in production code paths. ✓ (lints enforce workspace-wide). - pearlite-audit reports no §13 violations. ✓ What's NOT in this chunk (deferred per Plan §6.1): - Property tests with proptest — Plan §6.1 doesn't list any property test for pearlite-schema (proptest gates apply to pearlite-state §6.2 and pearlite-diff §6.3). Verification: - cargo test -p pearlite-schema (14 passed; 0 failed) - cargo doc -p pearlite-schema --no-deps (zero warnings) - cargo clippy --workspace --all-targets -- -D warnings (zero warnings) - cargo fmt --all --check - scripts/ci/check-spdx.sh - pearlite-audit check . (1 check, 0 violations) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9b9c8e0 commit a6d8358

4 files changed

Lines changed: 68 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 26 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ time = { version = "0.3", features = ["serde", "formatting", "parsing", "serde-w
3636
tracing = "0.1"
3737
tracing-subscriber = "0.3"
3838
clap = { version = "4", features = ["derive", "env", "wrap_help"] }
39-
schemars = "0.8"
39+
schemars = "1"
4040
sha2 = "0.10"
4141
tempfile = "3"
4242
rayon = "1"

crates/pearlite-schema/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ toml = { workspace = true }
1717
time = { workspace = true }
1818
schemars = { workspace = true }
1919
thiserror = { workspace = true }
20+
21+
[dev-dependencies]
22+
serde_json = { workspace = true }

crates/pearlite-schema/src/lib.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,41 @@ pub use services::ServicesDecl;
3636
pub use snapshots::SnapshotPolicy;
3737
pub use users::{HomeManagerDecl, HomeManagerMode, UserDecl};
3838
pub use validate::validate;
39+
40+
#[cfg(test)]
41+
#[allow(
42+
clippy::expect_used,
43+
clippy::unwrap_used,
44+
clippy::panic,
45+
reason = "tests may use expect()/unwrap()/panic!() per Plan §4.2 + CLAUDE.md"
46+
)]
47+
mod cross_cutting_tests {
48+
use super::*;
49+
50+
const FULL: &str = include_str!("../../../fixtures/schema/host_full.toml");
51+
52+
/// Plan §6.1 acceptance: emitted JSON Schema is Draft 2020-12.
53+
#[test]
54+
fn schemars_output_is_draft_2020_12() {
55+
let schema = schemars::schema_for!(DeclaredState);
56+
let json = serde_json::to_value(&schema).expect("serialize schema");
57+
let dollar_schema = json
58+
.get("$schema")
59+
.and_then(|v| v.as_str())
60+
.expect("$schema field present in emitted JSON Schema");
61+
assert!(
62+
dollar_schema.contains("2020-12"),
63+
"expected Draft 2020-12, got: {dollar_schema}"
64+
);
65+
}
66+
67+
/// Plan §6.1 acceptance: a representative resolved.toml fixture
68+
/// round-trips without loss.
69+
#[test]
70+
fn declared_state_round_trips_through_toml() {
71+
let original = from_resolved_toml(FULL).expect("parse full fixture");
72+
let serialized = toml::to_string(&original).expect("serialize");
73+
let reparsed = from_resolved_toml(&serialized).expect("re-parse serialized");
74+
assert_eq!(original, reparsed, "TOML round-trip must be lossless");
75+
}
76+
}

0 commit comments

Comments
 (0)