MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / policy_supersede_older

Function policy_supersede_older

crates/openshell-server/src/persistence/tests.rs:737–787  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

735
736#[tokio::test]
737async fn policy_supersede_older() {
738 let store = test_store().await;
739
740 let payload = SandboxPolicy::default().encode_to_vec();
741 store
742 .put_policy_revision("p1", "sandbox-1", 1, &payload, "h1")
743 .await
744 .unwrap();
745 store
746 .put_policy_revision("p2", "sandbox-1", 2, &payload, "h2")
747 .await
748 .unwrap();
749 store
750 .put_policy_revision("p3", "sandbox-1", 3, &payload, "h3")
751 .await
752 .unwrap();
753
754 // Mark v1 as loaded.
755 store
756 .update_policy_status("sandbox-1", 1, "loaded", None, Some(1000))
757 .await
758 .unwrap();
759
760 // Supersede all older revisions (pending + loaded) before v3.
761 let count = store
762 .supersede_older_policies("sandbox-1", 3)
763 .await
764 .unwrap();
765 assert_eq!(count, 2); // v1 (loaded) + v2 (pending) both < v3
766
767 let v1 = store
768 .get_policy_by_version("sandbox-1", 1)
769 .await
770 .unwrap()
771 .unwrap();
772 assert_eq!(v1.status, "superseded");
773
774 let v2 = store
775 .get_policy_by_version("sandbox-1", 2)
776 .await
777 .unwrap()
778 .unwrap();
779 assert_eq!(v2.status, "superseded");
780
781 let v3 = store
782 .get_policy_by_version("sandbox-1", 3)
783 .await
784 .unwrap()
785 .unwrap();
786 assert_eq!(v3.status, "pending"); // still pending (not < 3)
787}
788
789#[tokio::test]
790async fn policy_list_ordered_by_version_desc() {

Callers

nothing calls this directly

Calls 5

test_storeFunction · 0.70
put_policy_revisionMethod · 0.45
update_policy_statusMethod · 0.45
get_policy_by_versionMethod · 0.45

Tested by

no test coverage detected