astrid-runtime/astrid · error
audit fixture
Error message
audit fixture
What it means
The message "audit fixture" is the expect() context on std::fs::write(principal_home.audit_dir().join("entry"), b"audit") at audit_retirement_tests.rs:13. It is not a library error: it is a test-arrangement step that seeds one audit entry file so retire_legacy_audit_dir() has a non-empty legacy tree to migrate. fs::write returns io::Error, and the expect converts a failure (directory missing, permission denied, etc.) into a panic with this message. If it fires, the fixture directory was not created by the preceding ensure() call or the write itself failed.
Source
Thrown at crates/astrid-kernel/src/audit_retirement_tests.rs:13
use super::{preflight_legacy_audit_sources, require_audit_integrity, retire_legacy_audit_dir};
use astrid_audit::ChainVerificationResult;
use astrid_core::SessionId;
use astrid_core::dirs::AstridHome;
#[test]
fn audit_retirement_validates_tree_and_removes_only_verified_source() {
let directory = tempfile::tempdir().expect("temporary home");
let home = AstridHome::from_path(directory.path().join(".astrid"));
home.ensure().expect("home layout");
let principal_home = home.principal_home(&astrid_core::PrincipalId::default());
principal_home.ensure().expect("legacy principal layout");
std::fs::write(principal_home.audit_dir().join("entry"), b"audit").expect("audit fixture");
retire_legacy_audit_dir(&home, &principal_home.audit_dir()).expect("retire audit source");
assert!(!principal_home.audit_dir().exists());
assert!(
!home
.migrations_dir()
.join("audit-principal-home.retired")
.exists()
);
}
#[cfg(unix)]
#[test]
fn audit_retirement_rejects_redirects_before_removal() {
let directory = tempfile::tempdir().expect("temporary home");
let home = AstridHome::from_path(directory.path().join(".astrid"));
home.ensure().expect("home layout");
let principal_home = home.principal_home(&astrid_core::PrincipalId::default());View on GitHub (pinned to affd8760f4)
Solutions
- Verify principal_home.ensure() (line 12) actually creates audit_dir; if the test reached line 13, inspect ensure() for a dropped create_dir_all of the audit directory.
- Manually confirm the tempdir is writable: create the same path structure in a shell under $TMPDIR.
- If audit_dir returns a changed/incorrect path, fix the path construction in PrincipalHome::audit_dir().
- Add create_dir_all(principal_home.audit_dir()) before the write only as a local diagnostic, not a fix.
Example fix
// before
std::fs::write(principal_home.audit_dir().join("entry"), b"audit").expect("audit fixture");
// after
let entry = principal_home.audit_dir().join("entry");
std::fs::create_dir_all(principal_home.audit_dir()).expect("audit dir");
std::fs::write(&entry, b"audit").unwrap_or_else(|e| panic!("audit fixture: write {}: {e}", entry.display())); Defensive patterns
Strategy: validation
Validate before calling
let audit_dir = principal_home.audit_dir();
if !audit_dir.is_dir() {
panic!("audit fixture precondition: {} is not a directory", audit_dir.display());
}
// proceed with std::fs::write Type guard
fn is_writable_dir(p: &std::path::Path) -> bool {
p.is_dir() && std::fs::read_dir(p).is_ok()
} Try / catch
match std::fs::write(principal_home.audit_dir().join("entry"), b"audit") {
Ok(()) => {}
Err(e) => panic!("audit fixture: {e}"),
} Prevention
- Create the target directory (create_dir_all) before fs::write in fixtures.
- Keep PrincipalHome::ensure() responsible for creating audit_dir and test that invariant separately.
- Use error-bearing panic! helpers instead of bare .expect("...") for fixture writes.
When it happens
Trigger: std::fs::write fails when principal_home.audit_dir().join("entry") cannot be written: the audit_dir was not created by principal_home.ensure(), the path points through a symlink or read-only location, or disk/permission errors occur in the tempdir.
Common situations: A regression in PrincipalHome::ensure() that no longer creates audit_dir before the test writes into it; running tests under a user lacking write access to the OS temp directory; a path-construction bug that puts 'entry' under a nonexistent nested directory.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- outside fixture
- directory symlink {} not allowed in capsule source tree (ref
- mountpoint is already registered: {}
- failed to replace signed capsule archive: {error}
- capsule path escaped source root
AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09).
Data as JSON: /api/errors/0fcc8bd71647d4ae.
Report an issue: GitHub.