Skip to main content

arkhe_runtime_testkit/
shrink.rs

1//! Scope-based shrinker — TypeCode-region per-shrink path.
2//!
3//! Runs a separate shrink path per TypeCode region. For example, a failure in
4//! the core Component range (`0x0003_0000..=0x0003_0EFF`) is minimized within
5//! that range only rather than migrated into the shell-scoped range, which
6//! keeps the originating region pinned.
7
8/// Shrink scope marker — TypeCode-region dispatch key for shrink paths.
9#[non_exhaustive]
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum ShrinkScope {
12    /// `0x0003_0000..=0x0003_0EFF`
13    CoreComponent,
14    /// `0x0003_0F00..=0x0003_FFFF`
15    CoreEvent,
16    /// `0x0002_0001..=0x0002_03FF`
17    CanonicalVerb,
18    /// `0x0002_0400..=0x0002_FFFF`
19    ShellVerb,
20    /// `0x0100_0000..=0xEFFF_FFFF`
21    ShellScoped,
22    /// `0xF000_0000..=0xFFFF_FFFF`
23    DebugTest,
24}
25
26impl ShrinkScope {
27    /// Classify a raw TypeCode to its shrink scope.
28    pub fn of(type_code: u32) -> Option<Self> {
29        use arkhe_forge_core::typecode::*;
30        match type_code {
31            c if (CORE_COMPONENT.0..=CORE_COMPONENT.1).contains(&c) => Some(Self::CoreComponent),
32            c if (CORE_EVENT.0..=CORE_EVENT.1).contains(&c) => Some(Self::CoreEvent),
33            c if (CORE_VERB_CANONICAL.0..=CORE_VERB_CANONICAL.1).contains(&c) => {
34                Some(Self::CanonicalVerb)
35            }
36            c if (SHELL_VERB.0..=SHELL_VERB.1).contains(&c) => Some(Self::ShellVerb),
37            c if (SHELL_SCOPED.0..=SHELL_SCOPED.1).contains(&c) => Some(Self::ShellScoped),
38            c if (DEBUG_TEST.0..=DEBUG_TEST.1).contains(&c) => Some(Self::DebugTest),
39            _ => None,
40        }
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn classify_core_component() {
50        assert_eq!(
51            ShrinkScope::of(0x0003_0001),
52            Some(ShrinkScope::CoreComponent)
53        );
54    }
55
56    #[test]
57    fn classify_core_event() {
58        assert_eq!(ShrinkScope::of(0x0003_0F01), Some(ShrinkScope::CoreEvent));
59    }
60
61    #[test]
62    fn classify_debug_test() {
63        assert_eq!(ShrinkScope::of(0xFFFF_FFFF), Some(ShrinkScope::DebugTest));
64    }
65}