{"record":{"id":"a12a36093a131253","repo":"astrid-runtime/astrid","slug":"home-layout","errorCode":null,"errorMessage":"home layout","messagePattern":"home layout","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-kernel/src/audit_retirement_tests.rs","lineNumber":10,"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\");","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-kernel/src/audit_retirement_tests.rs#L1-L28","documentation":"Continuation of the same test setup: after creating the temp dir, `home.ensure()` must create the `.astrid` home layout (including the audit dir). The `expect(\"home layout\")` fires when `ensure` returns an `Err` — directory creation or the audit-dir layout step failed on the constructed path.","triggerScenarios":"Calling `AstridHome::from_path(tempdir/.astrid).ensure()` when mkdir of the home or `audit_dir` fails: nested-path permission problems, filesystem errors inside the temp dir, or a bug in `ensure` not creating parent directories (`audit_dir().join(\"entry\")` write would also fail later).","commonSituations":"A regression in `AstridHome::ensure` (missing recursive create), path-length or permission issues on exotic temp filesystems, or `principal_home.ensure()`/`audit_dir()` paths computed before the parent exists.","solutions":["Verify `ensure` creates all parent directories recursively before the audit dir.","Check the `audit_dir` path is under the ensured home, not an absolute path outside the temp tree.","Inspect the underlying io::Error from `ensure` — surface it in the panic message.","If the test filesystem is unusual, run against a standard writable temp dir via TMPDIR."],"exampleFix":"// before\nhome.ensure().expect(\"home layout\");\n// after\nhome.ensure().unwrap_or_else(|e| panic!(\"home layout creation failed at {:?}: {e}\", home.path()));","handlingStrategy":"validation","validationCode":"// Rust: confirm the home path is inside the temp dir before ensure()\nlet home = AstridHome::from_path(directory.path().join(\".astrid\"));\nassert!(home.path().starts_with(directory.path()), \"home must live under tempdir\");","typeGuard":null,"tryCatchPattern":"// Rust: surface the io error source on ensure failure\nhome.ensure().unwrap_or_else(|e| panic!(\"AstridHome::ensure failed for {:?}: {e}\", home.path()));","preventionTips":["Implement ensure() with recursive directory creation (create_dir_all).","Derive audit_dir from the home root so parents always exist first.","Test AstridHome layout creation on its own before higher-level tests depend on it.","Keep io errors attached to panics via context, never bare expects on setup."],"tags":["rust","test-setup","filesystem","directory-creation"],"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"}