-
-
Notifications
You must be signed in to change notification settings - Fork 96
Instant for internal calculations #1861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughReplaces primitive time utilities with epoch/clock abstractions: adds temporal helpers (getEpoch, epochToClock, clockToEpoch, etc.), refactors RuntimeState to use DayMs/EpochMs (adding epoch field), updates logger and tests to use new types, removes legacy time functions, and adds DST-aware Vitest global setup. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (13)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (6)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2024-10-08T20:08:54.932ZApplied to files:
🧬 Code graph analysis (2)apps/server/src/stores/runtimeState.ts (2)
apps/server/src/utils/__tests__/temporal.test.ts (1)
🔇 Additional comments (10)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
c47db98 to
99ae166
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/server/src/stores/runtimeState.ts (1)
257-269: Runtime guard doesn't properly narrow type before non-nullable assertion.RestorePoint's
startEpochis correctly typed asMaybe<EpochMs>in the type definition, so updating RestorePoint is unnecessary. However, the guard condition(startEpoch === null || typeof startEpoch === 'number')allows null to pass, then the assertionstartEpoch as EpochMsunsafely casts the potentially-null value to non-nullable. Change the guard totypeof startEpoch === 'number'to truly narrow the type, or explicitly handle the null case in the assignment.
🧹 Nitpick comments (1)
apps/server/src/utils/__tests__/temporal.test.ts (1)
5-18: Consider removing or deprecating the referencetimeNow()helper.The comment states this is "here until it is no longer needed for reference." If the new
epochToClockimplementation is verified and stable, consider removing this helper in a follow-up to reduce maintenance burden.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
packages/types/src/definitions/core/TimeUnits.type.tsis excluded by none and included by nonepackages/types/src/index.tsis excluded by none and included by nonepackages/types/src/utils/utils.type.tsis excluded by none and included by none
📒 Files selected for processing (13)
apps/server/src/api-data/automation/__tests__/automation.service.test.ts(8 hunks)apps/server/src/classes/Logger.ts(2 hunks)apps/server/src/services/__tests__/timerUtils.test.ts(9 hunks)apps/server/src/services/restore-service/__tests__/restore.parser.test.ts(3 hunks)apps/server/src/services/restore-service/__tests__/restore.service.test.ts(5 hunks)apps/server/src/services/restore-service/restore.type.ts(2 hunks)apps/server/src/stores/__mocks__/runtimeState.mocks.ts(1 hunks)apps/server/src/stores/runtimeState.ts(15 hunks)apps/server/src/utils/__tests__/temporal.test.ts(1 hunks)apps/server/src/utils/temporal.ts(1 hunks)apps/server/src/utils/time.ts(0 hunks)apps/server/vite.config.ts(1 hunks)apps/server/vitest.global-setup.ts(1 hunks)
💤 Files with no reviewable changes (1)
- apps/server/src/utils/time.ts
🧰 Additional context used
🧬 Code graph analysis (4)
apps/server/src/classes/Logger.ts (1)
apps/server/src/utils/temporal.ts (2)
epochToClock(34-38)getEpoch(8-8)
apps/server/src/utils/__tests__/temporal.test.ts (1)
apps/server/src/utils/temporal.ts (3)
getEpoch(8-8)epochToClock(34-38)clockToEpoch(18-24)
apps/server/src/api-data/automation/__tests__/automation.service.test.ts (2)
apps/server/src/stores/__mocks__/runtimeState.mocks.ts (1)
makeRuntimeStateData(56-58)apps/server/src/api-data/automation/automation.service.ts (1)
testConditions(71-124)
apps/server/src/stores/__mocks__/runtimeState.mocks.ts (1)
apps/server/src/stores/runtimeState.ts (1)
RuntimeState(45-70)
🔇 Additional comments (14)
apps/server/vitest.global-setup.ts (1)
1-3: LGTM!The global setup correctly establishes a consistent timezone for DST-aware temporal testing. The timezone choice is well-documented.
apps/server/src/services/restore-service/restore.type.ts (1)
1-11: LGTM!The type refinement from
MaybeNumbertoMaybe<EpochMs>strengthens type safety for epoch-based timestamps. The change is consistent with the broader temporal abstraction introduced in this PR.apps/server/vite.config.ts (1)
1-8: LGTM!The configuration correctly references the new global setup file, enabling consistent timezone handling across all tests.
apps/server/src/services/restore-service/__tests__/restore.service.test.ts (1)
1-128: LGTM!The test fixtures have been correctly updated with explicit
EpochMscasts to align with the refinedRestorePointtype. The changes are consistent across all test cases and maintain existing test coverage.apps/server/src/api-data/automation/__tests__/automation.service.test.ts (1)
1-316: LGTM!Test fixtures have been consistently updated to cast
clockvalues asDayMs, aligning with the temporal type system. The changes maintain test coverage while improving type safety.apps/server/src/classes/Logger.ts (2)
7-7: LGTM!The import update correctly references the new temporal utilities.
69-78: LGTM!The timestamp generation has been successfully migrated to use the epoch-based temporal abstraction. The
epochToClock(getEpoch())pattern correctly derives the clock time with timezone awareness for logging purposes.apps/server/src/services/__tests__/timerUtils.test.ts (1)
1-1296: LGTM!The test file has been correctly updated to use
DayMstyping for clock values and mutations. The explicit casts after arithmetic operations maintain type safety while preserving the test logic.apps/server/src/services/restore-service/__tests__/restore.parser.test.ts (1)
1-67: LGTM!The test has been correctly updated to use
EpochMstyping in valid test fixtures. The invalid test cases appropriately continue using plain numbers to verify validation logic.apps/server/src/stores/__mocks__/runtimeState.mocks.ts (1)
1-7: LGTM!The mock state correctly incorporates the new
epochfield and applies proper type casts for the brandedDayMsandEpochMstypes, aligning with the updatedRuntimeStateinterface.apps/server/src/stores/runtimeState.ts (2)
72-77: Module-level side effect during import.
getEpoch()andepochToClock()are called at module load time to initializestartupEpochandstartupClock. This captures the timestamp when the module is first imported, which may be significantly earlier than when the runtime actually starts. Verify this is the intended behavior.
532-535: LGTM on day offset calculation.The calculation correctly uses the epoch difference between current time and start time to determine how many days have passed since the runtime started.
apps/server/src/utils/temporal.ts (2)
18-24: LGTM onclockToEpochlogic.The implementation correctly derives the day boundary from the current epoch and adds the clock offset. The use of
epochToClock(now)here is appropriate since we need the current day's boundary.
1-8: Clean type-safe API with proper overloads.Good use of function overloads to maintain type narrowing for null vs non-null inputs. The branded types (
EpochMs,DayMs) provide compile-time safety for time value semantics.
|
Hey @alex-Arc , the code looks fine to me, the rabbit made some good observations lets chat! |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
InstantruntimeStateand drive clock from that