Skip to content
Merged
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
41 changes: 37 additions & 4 deletions pkgs/id/src/world_doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,17 @@ pub fn validate_journal_file(path: &Path) -> Result<(usize, u32)> {
version: created_version,
} => {
anyhow::ensure!(
index == 0,
entries == 0,
"entry {} is `Created`, but it is not the first entry",
index + 1
);
anyhow::ensure!(
*created_version <= MAX_JOURNAL_VERSION,
"journal format version {created_version} is newer than this binary supports ({MAX_JOURNAL_VERSION})"
(JOURNAL_VERSION..=MAX_JOURNAL_VERSION).contains(created_version),
"journal format version {created_version} is not one this binary supports ({JOURNAL_VERSION}..={MAX_JOURNAL_VERSION})"
);
version = Some(*created_version);
}
_ if index == 0 => {
_ if entries == 0 => {
anyhow::bail!("the first entry is not `Created`");
}
_ => {}
Expand Down Expand Up @@ -545,6 +545,39 @@ mod tests {
std::fs::remove_dir_all(&dir).ok();
}

#[test]
fn a_journal_version_zero_and_blank_lines_match_restore() {
// #1598: restore (world/core.rs) requires version 1..=MAX and reads
// the first *parsed* entry (world_store skips blank lines); doctor
// must agree on both.
let dir = std::env::temp_dir().join(format!("id-doctor-1598-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let path = dir.join("journal.jsonl");
let created = |version: u32| {
serde_json::json!({
"entry": "created",
"world_id": "w",
"version": version,
})
};

// Version 0 is below JOURNAL_VERSION: refused, like restore.
std::fs::write(&path, format!("{}\n", created(0))).unwrap();
assert!(validate_journal_file(&path).is_err());

// A leading blank line does not move the header: still valid.
std::fs::write(&path, format!("\n{}\n", created(JOURNAL_VERSION))).unwrap();
let (entries, version) = validate_journal_file(&path).unwrap();
assert_eq!((entries, version), (1, JOURNAL_VERSION));

// A leading blank line does not hide a missing header either.
let bad = serde_json::json!({"entry": "caps_granted", "granted": []});
std::fs::write(&path, format!("\n{bad}\n")).unwrap();
assert!(validate_journal_file(&path).is_err());

std::fs::remove_dir_all(&dir).ok();
}

#[test]
fn a_warn_only_report_does_not_fail_the_exit_result() {
// Healthy inputs, except the resolved compiler differs from the
Expand Down
Loading