summaryrefslogtreecommitdiff
path: root/internal/tui
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-13 19:41:44 +0300
committerPaul Buetow <paul@buetow.org>2026-05-13 19:41:44 +0300
commit0b454f367374e8cb97927627dacd0f1b216fe5ad (patch)
tree7e99ee96ee24ad31fe67e0fee0b4824f16425163 /internal/tui
parent7b4f74ab11a2504d107372afebdfd77dec59ea42 (diff)
introduce Accumulator interface in statsengine to separate ingestion from snapshot-building
Define statsengine.Accumulator (Ingest + Reset) to represent the event-accumulation responsibility separately from runtime.SnapshotSource (Snapshot), which handles the read side. This reduces the SRP violation in Engine: callers that only push events now hold an Accumulator; callers that only read statistics hold a SnapshotSource. - Add Accumulator interface and compile-time assertion in statsengine/engine.go - Add EventIngester type alias (= statsengine.Accumulator) in runtime/runtime.go with a compile-time assertion, so callers in the runtime layer can reference the ingestion contract without importing statsengine directly - Split tuiRuntime.engine field into accumulator + snapSource so the event-loop callback holds Accumulator and wireRuntimeBindings passes SnapshotSource to SetDashboardSnapshotSource — making each consumer's dependency explicit - Simplify resetDashboardSnapshotSource in tui.go to cast for interface{ Reset() } independently of Snapshot(), removing the combined ad-hoc interface check Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/tui')
-rw-r--r--internal/tui/tui.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/internal/tui/tui.go b/internal/tui/tui.go
index 695bd02..b73fbf8 100644
--- a/internal/tui/tui.go
+++ b/internal/tui/tui.go
@@ -226,22 +226,24 @@ func (r *runtimeBindings) advanceFilterEpoch() uint64 {
}
// resetDashboardSnapshotSource resets the dashboard snapshot source if it
-// implements the resettable interface, then returns a fresh snapshot. Errors
-// from Snapshot are silently dropped since callers handle a nil snapshot.
+// implements the Resetter contract (i.e. exposes Reset()), then returns a
+// fresh snapshot. The check is intentionally narrow — only Reset() is required
+// so that test doubles and future sources can satisfy it without also
+// implementing Ingest (which belongs to statsengine.Accumulator and is not
+// needed here). Errors from Snapshot are silently dropped since callers handle
+// a nil snapshot.
func (r *runtimeBindings) resetDashboardSnapshotSource() *statsengine.Snapshot {
src := r.dashboardSnapshotSource()
if src == nil {
return nil
}
- if resettable, ok := src.(interface {
- Reset()
- Snapshot() (*statsengine.Snapshot, error)
- }); ok {
+ // statsengine.Accumulator satisfies this interface; any other source that
+ // exposes Reset() (e.g. test fakes) also qualifies.
+ if resettable, ok := src.(interface{ Reset() }); ok {
resettable.Reset()
- snap, _ := resettable.Snapshot()
- return snap
}
- return nil
+ snap, _ := src.Snapshot()
+ return snap
}
// RuntimeBindingsFromContext returns the full TraceRuntimeBindings when the