{"record":{"id":"0fcc8bd71647d4ae","repo":"astrid-runtime/astrid","slug":"audit-fixture","errorCode":null,"errorMessage":"audit fixture","messagePattern":"audit fixture","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-kernel/src/audit_retirement_tests.rs","lineNumber":13,"sourceCode":"use super::{preflight_legacy_audit_sources, require_audit_integrity, retire_legacy_audit_dir};\nuse astrid_audit::ChainVerificationResult;\nuse astrid_core::SessionId;\nuse astrid_core::dirs::AstridHome;\n\n#[test]\nfn audit_retirement_validates_tree_and_removes_only_verified_source() {\n    let directory = tempfile::tempdir().expect(\"temporary home\");\n    let home = AstridHome::from_path(directory.path().join(\".astrid\"));\n    home.ensure().expect(\"home layout\");\n    let principal_home = home.principal_home(&astrid_core::PrincipalId::default());\n    principal_home.ensure().expect(\"legacy principal layout\");\n    std::fs::write(principal_home.audit_dir().join(\"entry\"), b\"audit\").expect(\"audit fixture\");\n\n    retire_legacy_audit_dir(&home, &principal_home.audit_dir()).expect(\"retire audit source\");\n    assert!(!principal_home.audit_dir().exists());\n    assert!(\n        !home\n            .migrations_dir()\n            .join(\"audit-principal-home.retired\")\n            .exists()\n    );\n}\n\n#[cfg(unix)]\n#[test]\nfn audit_retirement_rejects_redirects_before_removal() {\n    let directory = tempfile::tempdir().expect(\"temporary home\");\n    let home = AstridHome::from_path(directory.path().join(\".astrid\"));\n    home.ensure().expect(\"home layout\");\n    let principal_home = home.principal_home(&astrid_core::PrincipalId::default());","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-kernel/src/audit_retirement_tests.rs#L1-L31","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nstd::fs::write(principal_home.audit_dir().join(\"entry\"), b\"audit\").expect(\"audit fixture\");\n// after\nlet entry = principal_home.audit_dir().join(\"entry\");\nstd::fs::create_dir_all(principal_home.audit_dir()).expect(\"audit dir\");\nstd::fs::write(&entry, b\"audit\").unwrap_or_else(|e| panic!(\"audit fixture: write {}: {e}\", entry.display()));","handlingStrategy":"validation","validationCode":"let audit_dir = principal_home.audit_dir();\nif !audit_dir.is_dir() {\n    panic!(\"audit fixture precondition: {} is not a directory\", audit_dir.display());\n}\n// proceed with std::fs::write","typeGuard":"fn is_writable_dir(p: &std::path::Path) -> bool {\n    p.is_dir() && std::fs::read_dir(p).is_ok()\n}","tryCatchPattern":"match std::fs::write(principal_home.audit_dir().join(\"entry\"), b\"audit\") {\n    Ok(()) => {}\n    Err(e) => panic!(\"audit fixture: {e}\"),\n}","preventionTips":["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."],"tags":["rust","filesystem","test-fixture","file-write"],"backgroundTag":"file-write-failed","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}