astrid-runtime/astrid · error

preserved

Error message

preserved

What it means

Panic from `std::fs::read(other_home.audit_dir().join("entry")).expect("preserved")` in the assertion phase of the same test, verifying the legacy audit entry survived the failed boot untouched. The expect fires when the entry file cannot be read back.

Source

Thrown at crates/astrid-kernel/src/audit_retirement_tests.rs:87

    home.ensure().expect("home layout");
    let other = astrid_core::PrincipalId::new("other".to_owned()).expect("principal id");
    let other_home = home.principal_home(&other);
    other_home.ensure().expect("legacy principal layout");
    std::fs::write(other_home.audit_dir().join("entry"), b"audit").expect("non-empty audit");
    let default_source = home
        .principal_home(&astrid_core::PrincipalId::default())
        .audit_dir();

    let error = preflight_legacy_audit_sources(&home, &default_source)
        .expect_err("unhandled non-empty source must block boot");
    assert!(
        error
            .to_string()
            .contains("only the default principal source")
    );
    assert!(other_home.audit_dir().exists());
    assert_eq!(
        std::fs::read(other_home.audit_dir().join("entry")).expect("preserved"),
        b"audit"
    );
}

#[test]
fn audit_boot_allows_empty_non_default_audit_directory() {
    let directory = tempfile::tempdir().expect("temporary home");
    let home = AstridHome::from_path(directory.path().join(".astrid"));
    home.ensure().expect("home layout");
    let other = astrid_core::PrincipalId::new("other".to_owned()).expect("principal id");
    let other_home = home.principal_home(&other);
    other_home.ensure().expect("legacy principal layout");
    let default_source = home
        .principal_home(&astrid_core::PrincipalId::default())
        .audit_dir();
    preflight_legacy_audit_sources(&home, &default_source)
        .expect("empty non-default audit must not refuse cutover");
    assert!(other_home.audit_dir().exists());

View on GitHub (pinned to affd8760f4)

Solutions

  1. Check whether preflight_legacy_audit_sources (or boot) mutates/deletes the non-default audit directory — preservation is the contract under test.
  2. Confirm the same path is used for write and read (no rename of audit_dir).
  3. Re-run the test in isolation to rule out cross-test interference on shared temp state.
  4. Inspect the io::Error: NotFound means the code under test removed the file.

Example fix

// before
std::fs::read(other_home.audit_dir().join("entry")).expect("preserved")
// after
let bytes = std::fs::read(other_home.audit_dir().join("entry"))
    .unwrap_or_else(|e| panic!("preserved audit entry unreadable: {e}"));
Defensive patterns

Strategy: validation

Validate before calling

let entry = other_home.audit_dir().join("entry");
assert!(entry.exists(), "audit entry was not preserved");

Try / catch

let bytes = std::fs::read(&entry)
    .unwrap_or_else(|e| panic!("preserved entry unreadable ({e}) — was it deleted by preflight?"));

Prevention

When it happens

Trigger: Reading `audit_dir/entry` after preflight when a prior assertion step deleted or moved the audit directory, or when the file was never written (earlier expect would have fired) and the path is wrong/removed by the code under test.

Common situations: A regression where the audit-retirement code deletes or rewrites non-default audit sources during preflight instead of leaving them preserved; path changes to `audit_dir()` between write and read.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09). Data as JSON: /api/errors/b69736f9faaee5d6. Report an issue: GitHub.