From d7eded97f088da6596a8c7dcf8108ae7bf7e311f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Fri, 8 May 2026 05:29:26 -0400 Subject: [PATCH] Track space timestamps --- crates/ely_browser_core/tests/spaces.rs | 47 ++++++++++++++++++++++++- crates/ely_domain/src/space.rs | 25 +++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/crates/ely_browser_core/tests/spaces.rs b/crates/ely_browser_core/tests/spaces.rs index c7338ef..a496ef9 100644 --- a/crates/ely_browser_core/tests/spaces.rs +++ b/crates/ely_browser_core/tests/spaces.rs @@ -1,7 +1,7 @@ use std::error::Error; use ely_browser_core::{BrowserCore, CoreError, InitialBrowserConfig}; -use ely_domain::{ProfileId, ProfileKind}; +use ely_domain::{ArchivePolicy, ProfileId, ProfileKind}; #[test] fn created_space_binds_current_profile_as_default() -> Result<(), Box> { @@ -21,6 +21,21 @@ fn created_space_binds_current_profile_as_default() -> Result<(), Box Ok(()) } +#[test] +fn created_space_records_creation_timestamps() -> Result<(), Box> { + let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; + let research_space_id = core.create_space("Research", "R", 0x9fc9a2)?; + let snapshot = core.snapshot()?; + let Some(research_space) = + snapshot.spaces.iter().find(|space| space.id() == &research_space_id) + else { + return Err("missing research space".into()); + }; + + assert_eq!(research_space.created_at(), research_space.updated_at()); + Ok(()) +} + #[test] fn space_default_profile_updates_with_profile_validation() -> Result<(), Box> { let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; @@ -44,3 +59,33 @@ fn space_default_profile_updates_with_profile_validation() -> Result<(), Box Result<(), Box> { + let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; + let work_space_id = core.snapshot()?.active_space_id; + let before_update = active_space_updated_at(&core, &work_space_id)?; + + core.set_space_archive_policy(&work_space_id, ArchivePolicy::IdleDays(7))?; + let after_archive_update = active_space_updated_at(&core, &work_space_id)?; + + let research_profile_id = core.create_profile("Research", 0x9fc9a2, ProfileKind::Standard)?; + core.set_space_default_profile(&work_space_id, &research_profile_id)?; + let after_profile_update = active_space_updated_at(&core, &work_space_id)?; + + assert!(after_archive_update > before_update); + assert!(after_profile_update > after_archive_update); + Ok(()) +} + +fn active_space_updated_at( + core: &BrowserCore, + space_id: &ely_domain::SpaceId, +) -> Result> { + let snapshot = core.snapshot()?; + let Some(space) = snapshot.spaces.iter().find(|space| space.id() == space_id) else { + return Err("missing space".into()); + }; + + Ok(space.updated_at()) +} diff --git a/crates/ely_domain/src/space.rs b/crates/ely_domain/src/space.rs index a077d76..92773bf 100644 --- a/crates/ely_domain/src/space.rs +++ b/crates/ely_domain/src/space.rs @@ -1,3 +1,5 @@ +use std::time::{Duration, SystemTime}; + use crate::{ProfileId, SpaceId}; #[derive(Clone, Debug, Eq, PartialEq)] @@ -14,6 +16,8 @@ pub struct Space { accent_hex: u32, default_profile_id: ProfileId, archive_policy: ArchivePolicy, + created_at: SystemTime, + updated_at: SystemTime, } impl Space { @@ -24,6 +28,7 @@ impl Space { accent_hex: u32, default_profile_id: ProfileId, ) -> Self { + let created_at = SystemTime::now(); Self { id: SpaceId::new(), name: name.into(), @@ -31,6 +36,8 @@ impl Space { accent_hex, default_profile_id, archive_policy: ArchivePolicy::Manual, + created_at, + updated_at: created_at, } } @@ -61,6 +68,7 @@ impl Space { pub fn set_default_profile_id(&mut self, profile_id: ProfileId) { self.default_profile_id = profile_id; + self.record_update(); } #[must_use] @@ -70,5 +78,22 @@ impl Space { pub fn set_archive_policy(&mut self, archive_policy: ArchivePolicy) { self.archive_policy = archive_policy; + self.record_update(); + } + + #[must_use] + pub fn created_at(&self) -> SystemTime { + self.created_at + } + + #[must_use] + pub fn updated_at(&self) -> SystemTime { + self.updated_at + } + + fn record_update(&mut self) { + let now = SystemTime::now(); + self.updated_at = + if now > self.updated_at { now } else { self.updated_at + Duration::from_nanos(1) }; } }