// Integration tests for relicario-server org-hook path classification. use relicario_server::{classify_path, PathClass}; #[test] fn protected_files_are_classified_protected() { assert_eq!(classify_path("members.json"), PathClass::Protected); assert_eq!(classify_path("collections.json"), PathClass::Protected); assert_eq!(classify_path("org.json"), PathClass::Protected); } #[test] fn item_write_yields_collection_slug() { assert_eq!( classify_path("items/prod/a1b2c3d4e5f6a1b2.enc"), PathClass::Item { collection: "prod".to_string() } ); } #[test] fn item_write_nested_slug_takes_leading_segment_only() { // Slugs cannot contain '/', so a 4-segment path is malformed → Rejected. assert_eq!( classify_path("items/prod/sub/x.enc"), PathClass::Rejected("items path must be items//.enc".to_string()) ); } #[test] fn key_blobs_and_manifest_are_unrestricted() { // keys/.enc and manifest.enc are written by org operations; the SIGNATURE // check (every commit must be signed by a current member) is the gate for them. assert_eq!(classify_path("keys/a1b2c3d4e5f6a1b2.enc"), PathClass::Unrestricted); assert_eq!(classify_path("manifest.enc"), PathClass::Unrestricted); } #[test] fn items_without_slug_segment_are_rejected() { // Flat items/.enc (the OLD, now-removed layout) is no longer valid. assert_eq!( classify_path("items/a1b2c3d4e5f6a1b2.enc"), PathClass::Rejected("items path must be items//.enc".to_string()) ); } #[test] fn empty_slug_segment_is_rejected() { assert_eq!( classify_path("items//x.enc"), PathClass::Rejected("empty collection slug in items path".to_string()) ); } use relicario_server::extract_schema_version; #[test] fn extract_schema_version_reads_field() { let json = r#"{ "schema_version": 3, "members": [] }"#; assert_eq!(extract_schema_version(json).unwrap(), 3); } #[test] fn extract_schema_version_errors_on_missing_field() { let json = r#"{ "members": [] }"#; assert!(extract_schema_version(json).is_err()); } #[test] fn extract_schema_version_errors_on_garbage() { assert!(extract_schema_version("not json").is_err()); }