Design file format 2 with a migration chain (doc::format: older formats upgraded step by step, newer refused with a message, out-of-range numbers and broken occurrence placements refused); a corpus of designs saved by the M0, components-era, joints-era and current builds that must open and evaluate as saved (two pre-versioning behaviour changes listed with their reasons); damaged and hostile variants of every corpus file never panic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AS5Tn3xieewUSg3uxrMVdL
This commit is contained in:
bherbruckandClaude Opus 5.5 committed 2026-10-08 11:37:33 +00:00
1 parent f50d743c55
commit f413a86d3d
27 files changed
+3109 -17

No files matched your search

+3 -16
View File
@@ -1113,7 +1113,7 @@ pub struct BrowserGroup {
}
fn default_format() -> String {
"solvecraft/1".into()
crate::format::format_string(crate::format::FORMAT)
}
fn default_units() -> String {
"mm".into()
@@ -1214,22 +1214,9 @@ impl Document {
self.components.iter().find(|c| c.id.to_string() == key || c.name == key).map(|c| c.id)
}
/// Read a design file's JSON (any format this build knows; older ones are upgraded).
pub fn from_json(s: &str) -> Result<Document> {
let mut d: Document = serde_json::from_str(s).map_err(|e| DocError::Invalid(format!("document: {e}")))?;
if d.features.len() > MAX_FEATURES || d.params.len() > MAX_PARAMS {
return Err(DocError::Invalid("document too large".into()));
}
// Feature inputs get parameter names (designs from before they had them).
let ids: Vec<u64> = d.features.iter().map(|f| f.id).collect();
for id in ids {
d.name_feature_inputs(id);
}
// Designs from before occurrences: every component gets one, in place.
let missing: Vec<(u64, u64)> =
d.components.iter().filter(|c| !d.occurrences.iter().any(|o| o.component == c.id)).map(|c| (c.id, c.parent)).collect();
for (c, p) in missing {
d.add_occurrence(c, p, crate::IDENTITY)?;
}
let d = crate::format::read(s)?;
if d.features.len() > MAX_FEATURES || d.params.len() > MAX_PARAMS {
return Err(DocError::Invalid("document too large".into()));
}