Skip to main content

webizen_render/pipeline/
temporal_contract.rs

1//! Typed, allocation-free temporal producer contracts for Webizen frame planning.
2//!
3//! Re-exports the canonical temporal producer contracts from
4//! `etalon_render::webizen_core::temporal_contract`.
5
6pub use etalon_render::webizen_core::temporal_contract::*;
7
8#[cfg(test)]
9mod tests {
10    use super::*;
11
12    fn extent() -> FrameExtent {
13        FrameExtent::new(640, 360).unwrap()
14    }
15
16    fn incomplete_contract(history: TemporalHistoryContract) -> TemporalFrameContract<'static> {
17        TemporalFrameContract::new(TemporalProducerContract::for_extent(extent()), history)
18    }
19
20    #[test]
21    fn extent_rejects_zero_dimensions_and_scales_like_qualia() {
22        assert_eq!(
23            FrameExtent::new(0, 360),
24            Err(TemporalContractError::InvalidExtent {
25                width: 0,
26                height: 360
27            })
28        );
29        assert_eq!(
30            FrameExtent::scaled(800, 450, 8_500).unwrap(),
31            FrameExtent::new(680, 382).unwrap()
32        );
33    }
34
35    #[test]
36    fn refusal_is_deterministic_and_prioritizes_missing_linear_depth() {
37        let contract = incomplete_contract(TemporalHistoryContract::first_frame(0));
38        assert_eq!(
39            contract.admit(extent()),
40            Err(TemporalCapabilityRefusal::MissingProducer {
41                resource: TemporalResource::LinearDepth
42            })
43        );
44    }
45
46    #[test]
47    fn policy_refuses_extent_mismatch_before_capability_checks() {
48        let contract = incomplete_contract(TemporalHistoryContract::first_frame(0));
49        assert_eq!(
50            contract.admit(FrameExtent::new(1280, 720).unwrap()),
51            Err(TemporalCapabilityRefusal::ExtentMismatch {
52                expected: FrameExtent::new(1280, 720).unwrap(),
53                actual: Some(extent()),
54            })
55        );
56    }
57
58    #[test]
59    fn capability_summary_can_test_full_policy_without_gpu_data() {
60        let admission = admit_capabilities(
61            TemporalProducerCapabilities::complete(extent()),
62            TemporalHistoryContract::continuing(7),
63            extent(),
64        );
65        assert_eq!(
66            admission,
67            Ok(TemporalAdmission {
68                reads_history: true,
69                reset_history: false,
70                publish_history: true,
71            })
72        );
73    }
74
75    #[test]
76    fn policy_requires_explicit_reset_and_publication() {
77        let capabilities = TemporalProducerCapabilities::complete(extent());
78        assert_eq!(
79            admit_capabilities(
80                capabilities,
81                TemporalHistoryContract {
82                    frame_index: 0,
83                    history_valid: false,
84                    reset_history: false,
85                    publication: HistoryPublication::Publish,
86                },
87                extent(),
88            ),
89            Err(TemporalCapabilityRefusal::HistoryResetRequired)
90        );
91        assert_eq!(
92            admit_capabilities(
93                capabilities,
94                TemporalHistoryContract {
95                    frame_index: 0,
96                    history_valid: true,
97                    reset_history: false,
98                    publication: HistoryPublication::Skip,
99                },
100                extent(),
101            ),
102            Err(TemporalCapabilityRefusal::PublicationRequired)
103        );
104    }
105
106    #[test]
107    fn reset_and_publication_state_are_explicit() {
108        let mut history = TemporalHistoryContract::first_frame(4);
109        assert!(history.reset_history);
110        assert!(!history.reads_history());
111        assert!(history.publish_history());
112        history = history.after_publication();
113        assert_eq!(history.frame_index, 5);
114        assert!(history.history_valid);
115        assert!(!history.publish_history());
116
117        let contract = incomplete_contract(history);
118        assert_eq!(
119            contract.admit(extent()),
120            Err(TemporalCapabilityRefusal::MissingProducer {
121                resource: TemporalResource::LinearDepth
122            })
123        );
124    }
125}