Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions VERIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ Outside `vv`:

## Falsifiability records

### semantic snapshot nesting can fail

Before the correction for #430, the focused
`artifact::snapshot::tests` library filter ran two cases: existing shallow
snapshot bytes passed, while serializing a 160-level linked value panicked
at `snapshot.rs` with `recursion limit exceeded`. The snapshot DTO had
already been constructed; its redundant byte parse imposed serde_json's
raw-reader nesting limit on that structured value.

Snapshot serialization now converts its structured value directly into the
canonical JSON domain. The checks excluding null and non-integer numbers
remain shared with raw parsing; raw parsing still checks duplicate keys.
The deep regression round-trips the complete snapshot and its content digest,
and the shallow regression compares exact bytes with the previous recipe.
All 221 LexLean library tests pass on release/v0.4 with ordinary test stacks.
This is library evidence, not a complete `vv` or consuming-app attestation.


Each gate below was made to fail by planting a defect, running the gate's command, recording the failure, and removing the defect. The observed lines are verbatim gate output (paths abbreviated to the repository root). `cargo xtask release-check` requires a `### <gate> can fail` record for every gate and audit named in `repo_model::release::GATES`.

### BS-15 render corpus materialization
Expand Down
4 changes: 3 additions & 1 deletion crates/lexlean/src/artifact/canonical_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ impl Json {
Self::from_serde(&value)
}

fn from_serde(value: &serde_json::Value) -> Result<Self, String> {
/// Convert an already structured value while retaining the canonical domain checks.
/// Raw byte inputs must use `parse` so duplicate keys are checked before decoding.
pub(crate) fn from_serde(value: &serde_json::Value) -> Result<Self, String> {
match value {
serde_json::Value::Null => Err("canonical JSON has no null".to_owned()),
serde_json::Value::Bool(b) => Ok(Self::Bool(*b)),
Expand Down
64 changes: 62 additions & 2 deletions crates/lexlean/src/artifact/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ impl SemanticSnapshot {
#[must_use]
pub fn to_json(&self) -> Json {
let value = serde_json::to_value(self).expect("snapshot DTO serializes");
let bytes = serde_json::to_vec(&value).expect("snapshot JSON serializes");
Json::parse(&bytes).expect("snapshot DTO uses the canonical JSON domain")
// The DTO already has unique object keys. Re-parsing its serialization
// imposes the raw JSON reader's nesting limit on accepted linked IR.
Json::from_serde(&value).expect("snapshot DTO uses the canonical JSON domain")
}

/// Canonical JSON file bytes, including LexLean's single final LF.
Expand Down Expand Up @@ -594,3 +595,62 @@ impl SnapshotAxiomPolicy {
&self.axioms
}
}

#[cfg(test)]
mod tests {
use super::*;

fn nested_snapshot(depth: usize) -> SemanticSnapshot {
let mut linked_ir = serde_json::json!("leaf");
for _ in 0..depth {
linked_ir = serde_json::Value::Array(vec![linked_ir]);
}
let digest = Sha256Digest::of(b"snapshot fixture");
SemanticSnapshot {
spec: "lexlean/semantic-snapshot/2".into(),
source_id: digest,
semantic_id: digest,
compiler_semantics_id: digest,
language: "1.2".into(),
modules: vec![SnapshotModule {
name: "Main".into(),
lean_module: "Main".into(),
origin: None,
imports: vec![],
glossary: vec![],
visible_packages: vec![],
source: SnapshotSource {
path: "src/Main.lex.tex".into(),
sha256: digest,
},
declarations: vec![],
core: None,
semantic: None,
linked_ir,
}],
lexicon_closure: serde_json::json!({}),
}
}

#[test]
fn canonical_snapshot_preserves_deep_linked_values() {
let snapshot = nested_snapshot(160);
let bytes = snapshot.canonical_bytes();
let mut reader = serde_json::Deserializer::from_slice(&bytes);
reader.disable_recursion_limit();
let restored = SemanticSnapshot::deserialize(&mut reader).expect("deep snapshot JSON");
reader.end().expect("complete snapshot");
assert_eq!(restored, snapshot);
assert_eq!(restored.canonical_bytes(), bytes);
assert_eq!(snapshot.snapshot_id(), Sha256Digest::of(&bytes));
}

#[test]
fn canonical_snapshot_preserves_existing_bytes() {
let snapshot = nested_snapshot(4);
let prior = Json::parse(&serde_json::to_vec(&snapshot).expect("snapshot JSON"))
.expect("canonical domain")
.to_file_bytes();
assert_eq!(snapshot.canonical_bytes(), prior);
}
}
Loading