bootstrap.rs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #[derive(Debug, Clone, Copy, PartialEq, Eq)]
  2. pub enum BootstrapPhase {
  3. CliEntry,
  4. FastPathVersion,
  5. StartupProfiler,
  6. SystemPromptFastPath,
  7. ChromeMcpFastPath,
  8. DaemonWorkerFastPath,
  9. BridgeFastPath,
  10. DaemonFastPath,
  11. BackgroundSessionFastPath,
  12. TemplateFastPath,
  13. EnvironmentRunnerFastPath,
  14. MainRuntime,
  15. }
  16. #[derive(Debug, Clone, PartialEq, Eq)]
  17. pub struct BootstrapPlan {
  18. phases: Vec<BootstrapPhase>,
  19. }
  20. impl BootstrapPlan {
  21. #[must_use]
  22. pub fn claude_code_default() -> Self {
  23. Self::from_phases(vec![
  24. BootstrapPhase::CliEntry,
  25. BootstrapPhase::FastPathVersion,
  26. BootstrapPhase::StartupProfiler,
  27. BootstrapPhase::SystemPromptFastPath,
  28. BootstrapPhase::ChromeMcpFastPath,
  29. BootstrapPhase::DaemonWorkerFastPath,
  30. BootstrapPhase::BridgeFastPath,
  31. BootstrapPhase::DaemonFastPath,
  32. BootstrapPhase::BackgroundSessionFastPath,
  33. BootstrapPhase::TemplateFastPath,
  34. BootstrapPhase::EnvironmentRunnerFastPath,
  35. BootstrapPhase::MainRuntime,
  36. ])
  37. }
  38. #[must_use]
  39. pub fn from_phases(phases: Vec<BootstrapPhase>) -> Self {
  40. let mut deduped = Vec::new();
  41. for phase in phases {
  42. if !deduped.contains(&phase) {
  43. deduped.push(phase);
  44. }
  45. }
  46. Self { phases: deduped }
  47. }
  48. #[must_use]
  49. pub fn phases(&self) -> &[BootstrapPhase] {
  50. &self.phases
  51. }
  52. }
  53. #[cfg(test)]
  54. mod tests {
  55. use super::{BootstrapPhase, BootstrapPlan};
  56. #[test]
  57. fn from_phases_deduplicates_while_preserving_order() {
  58. // given
  59. let phases = vec![
  60. BootstrapPhase::CliEntry,
  61. BootstrapPhase::FastPathVersion,
  62. BootstrapPhase::CliEntry,
  63. BootstrapPhase::MainRuntime,
  64. BootstrapPhase::FastPathVersion,
  65. ];
  66. // when
  67. let plan = BootstrapPlan::from_phases(phases);
  68. // then
  69. assert_eq!(
  70. plan.phases(),
  71. &[
  72. BootstrapPhase::CliEntry,
  73. BootstrapPhase::FastPathVersion,
  74. BootstrapPhase::MainRuntime,
  75. ]
  76. );
  77. }
  78. #[test]
  79. fn claude_code_default_covers_each_phase_once() {
  80. // given
  81. let expected = [
  82. BootstrapPhase::CliEntry,
  83. BootstrapPhase::FastPathVersion,
  84. BootstrapPhase::StartupProfiler,
  85. BootstrapPhase::SystemPromptFastPath,
  86. BootstrapPhase::ChromeMcpFastPath,
  87. BootstrapPhase::DaemonWorkerFastPath,
  88. BootstrapPhase::BridgeFastPath,
  89. BootstrapPhase::DaemonFastPath,
  90. BootstrapPhase::BackgroundSessionFastPath,
  91. BootstrapPhase::TemplateFastPath,
  92. BootstrapPhase::EnvironmentRunnerFastPath,
  93. BootstrapPhase::MainRuntime,
  94. ];
  95. // when
  96. let plan = BootstrapPlan::claude_code_default();
  97. // then
  98. assert_eq!(plan.phases(), &expected);
  99. }
  100. }