{"record":{"id":"b66fd8505d4380b1","repo":"astrid-runtime/astrid","slug":"non-empty-audit","errorCode":null,"errorMessage":"non-empty audit","messagePattern":"non-empty audit","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-kernel/src/audit_retirement_tests.rs","lineNumber":73,"sourceCode":"        SessionId::new(),\n        ChainVerificationResult {\n            valid: false,\n            entries_verified: 1,\n            issues: Vec::new(),\n        },\n    )];\n    assert!(require_audit_integrity(&invalid).is_err());\n}\n\n#[test]\nfn audit_boot_rejects_unhandled_non_default_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 other = astrid_core::PrincipalId::new(\"other\".to_owned()).expect(\"principal id\");\n    let other_home = home.principal_home(&other);\n    other_home.ensure().expect(\"legacy principal layout\");\n    std::fs::write(other_home.audit_dir().join(\"entry\"), b\"audit\").expect(\"non-empty audit\");\n    let default_source = home\n        .principal_home(&astrid_core::PrincipalId::default())\n        .audit_dir();\n\n    let error = preflight_legacy_audit_sources(&home, &default_source)\n        .expect_err(\"unhandled non-empty source must block boot\");\n    assert!(\n        error\n            .to_string()\n            .contains(\"only the default principal source\")\n    );\n    assert!(other_home.audit_dir().exists());\n    assert_eq!(\n        std::fs::read(other_home.audit_dir().join(\"entry\")).expect(\"preserved\"),\n        b\"audit\"\n    );\n}\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-kernel/src/audit_retirement_tests.rs#L55-L91","documentation":"Panic from `std::fs::write(other_home.audit_dir().join(\"entry\"), b\"audit\").expect(\"non-empty audit\")`. The test writes a sentinel audit entry file to make the legacy audit directory non-empty; the expect fires when the file write fails.","triggerScenarios":"Writing to `audit_dir/entry` when the audit directory does not exist (ensure not yet run), permissions deny write, or the path resolves to a directory named `entry`.","commonSituations":"Ordering mistakes where the audit dir isn't created before the write, read-only CI filesystems, or disk-full conditions during large test suites.","solutions":["Ensure the principal home (and thus audit dir) is created before writing the entry file.","Check permissions and disk space on the temp filesystem.","Verify `audit_dir()` points where expected (print the path) — a path mismatch is a common cause.","Handle the io::Error explicitly instead of expect in non-test code."],"exampleFix":"// before\nstd::fs::write(other_home.audit_dir().join(\"entry\"), b\"audit\").expect(\"non-empty audit\");\n// after\nstd::fs::create_dir_all(other_home.audit_dir()).expect(\"audit dir\");\nstd::fs::write(other_home.audit_dir().join(\"entry\"), b\"audit\").unwrap_or_else(|e| panic!(\"non-empty audit: {e}\"));","handlingStrategy":"validation","validationCode":"let dir = other_home.audit_dir();\nstd::fs::create_dir_all(&dir)?;\nassert!(dir.is_dir(), \"audit dir missing before write\");","typeGuard":null,"tryCatchPattern":"std::fs::write(path, b\"audit\")\n    .unwrap_or_else(|e| panic!(\"audit entry write failed: {e}\"));","preventionTips":["Create the audit directory before writing entries.","Confirm audit_dir() path with a debug print when tests fail.","Watch for ENOSPC/permission errors in noisy CI logs."],"tags":["filesystem","test","panic","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"}