hephaestus/crates/heph-core/src/clock.rs
Erich Blume bbac338f76
Some checks failed
Build / validate (pull_request) Failing after 3s
Scaffold cargo workspace + heph-core foundation
Kick off Phase 1 (v1 prototype) per tech-spec §11.1. Sets up the Cargo
workspace and the first TDD slice of heph-core:

- Migration runner + §4.5 SQLite schema (nodes, tasks, links, aliases,
  users, oplog, sync_state, conflicts), versioned via PRAGMA user_version.
- Clock-injected `Clock` trait (no ambient wall-clock reads; §2).
- `Store` trait + `LocalStore` SQLite backend with node create/get,
  bootstrapping the single local user (oidc_sub NULL, §13).
- Node model (kinds: doc/task/project/tag/journal).

Repo housekeeping: fill AGENTS.md Project Structure (last template TODO),
ignore /target, add self-bootstrapping .forgejo/scripts/build that runs
cargo fmt/clippy/test in CI (§9), changelog fragment.

Tests green: 4 unit tests (migration version, local-user idempotency,
create/get round-trip, missing-node None).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 18:52:15 -07:00

22 lines
671 B
Rust

//! Clock injection.
//!
//! `heph-core` never reads the ambient wall clock (tech-spec §2): the current
//! time is always supplied through a [`Clock`]. This keeps ranking and
//! recurrence deterministic and testable. The daemon wires in a real
//! system clock; tests wire in a [`FixedClock`].
/// Source of the current time, in epoch milliseconds.
pub trait Clock: Send + Sync {
/// Current time as epoch milliseconds.
fn now_ms(&self) -> i64;
}
/// A clock pinned to a fixed instant — for deterministic tests.
#[derive(Debug, Clone, Copy)]
pub struct FixedClock(pub i64);
impl Clock for FixedClock {
fn now_ms(&self) -> i64 {
self.0
}
}