Documentation
¶
Overview ¶
Package clock provides the Clock and IDGen interfaces, injected wherever time/ids are needed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface {
Now() time.Time
// Sleep blocks for d, returning early with ctx.Err() if ctx is cancelled
// or its deadline expires. d <= 0 returns immediately with nil (or
// ctx.Err() if already cancelled).
Sleep(ctx context.Context, d time.Duration) error
}
Clock supplies the current time and a deterministic sleep. Injected so tests can control both — engine logic NEVER reaches time.Now / time.Sleep directly (CLAUDE.md determinism invariant).
type CryptoIDGen ¶
type CryptoIDGen struct{}
CryptoIDGen is the production IDGen (128-bit crypto/rand, hex-encoded).
func (CryptoIDGen) NewRunID ¶
func (CryptoIDGen) NewRunID() string
type Fake ¶
Fake is a deterministic Clock+IDGen for tests. NewRunID returns IDs in order.
Fake is safe for concurrent use. The production System clock's Now/Sleep are goroutine-safe (time.Now / time.NewTimer), so the Clock contract permits concurrent callers — e.g. engine/agent_event_sink.go drives Sleep from per-delta-timer goroutines. mu guards the mutable T and i fields; construct Fake by named fields only (the zero-value mu is ready to use), and always use it via *Fake so the mutex is never copied.
func (*Fake) Advance ¶
Advance steps the fake clock forward by d. Slice 2.4 (retry / timeout tests) uses this to simulate elapsed time without real-time sleeps. Independent of testing/synctest — Fake.Now() returns f.T regardless of any synctest bubble's faked time.Now(). Whether retry tests use this method or synctest's time-fake is slice 2.4's decision; 2.1 ships only the explicit-control primitive.
func (*Fake) Sleep ¶
Sleep is the Fake's non-blocking deterministic sleeper — advances T by d (if the context is live) and returns immediately. Tests that drive retry orchestration use this; the post-loop f.Now() reads as if d had elapsed. A pre-cancelled or expired ctx returns ctx.Err() WITHOUT advancing T.
type IDGen ¶
type IDGen interface {
NewRunID() string
}
IDGen mints the run id — the only nondeterministic id in the runtime.