Add activity tracker server, Hyprland agent and Gitea image publishing
Test and publish / test (push) Successful in 2m38s
Test and publish / publish (push) Failing after 2m30s

The Go API on PostgreSQL ingests desktop, browser, presence, manual and
Health Auto Export events and serves activities and daily goal summaries.
The Hyprland agent records window focus, idle and lock intervals.

The CI workflow publishes adam-french.co.uk/adamf/activity-tracker to the
Gitea registry and rolls the web_server stack onto it. The image probes
itself through a new `tracker healthcheck` command, because distroless
has no wget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-14 20:38:12 +01:00
co-authored by Claude Opus 5.5
parent 0cbbb76dee
commit f4ce04875c
29 changed files with 2810 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
package ingest
import (
"encoding/json"
"strings"
"testing"
"time"
)
func TestNormalizeValidation(t *testing.T) {
now := time.Date(2026, 10, 14, 12, 0, 0, 0, time.UTC)
ok := Event{ID: "1", Kind: "app_focus", Label: "kitty", StartedAt: now.Add(-time.Hour), EndedAt: now}
tests := []struct {
name string
mutate func(*Event)
wantErr string
}{
{"valid", func(e *Event) {}, ""},
{"missing id", func(e *Event) { e.ID = "" }, "id"},
{"wrong kind", func(e *Event) { e.Kind = "tab_focus" }, "not accepted"},
{"reversed", func(e *Event) { e.EndedAt = e.StartedAt.Add(-time.Second) }, "before"},
{"future", func(e *Event) { e.EndedAt = now.Add(time.Hour) }, "future"},
{"too long", func(e *Event) { e.StartedAt = now.Add(-8 * 24 * time.Hour) }, "longer"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := ok
tt.mutate(&e)
acts, err := Desktop.Normalize(Batch{Events: []Event{e}}, now)
if tt.wantErr == "" {
if err != nil || len(acts) != 1 || acts[0].Source != "hyprland" {
t.Fatalf("got %+v, %v", acts, err)
}
return
}
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
t.Fatalf("got err %v, want containing %q", err, tt.wantErr)
}
})
}
}
func TestNormalizeHAE(t *testing.T) {
raw := `{"data":{
"workouts":[{"id":"W1","name":"Outdoor Walk","start":"2026-10-14 07:00:00 -0700","end":"2026-10-14 07:45:00 -0700","location":"Outdoor"}],
"metrics":[
{"name":"step_count","units":"count","data":[{"date":"2026-10-14 07:00:00 -0700","qty":812,"source":"iPhone"},{"date":"bad"}]},
{"name":"sleep_analysis","units":"hr","data":[{"sleepStart":"2026-10-13 23:10:00 -0700","sleepEnd":"2026-10-14 06:40:00 -0700","asleep":7.1}]}
]}}`
var p HAEPayload
if err := json.Unmarshal([]byte(raw), &p); err != nil {
t.Fatal(err)
}
acts, samples, err := NormalizeHAE(p)
if err != nil {
t.Fatal(err)
}
if len(acts) != 2 || len(samples) != 1 {
t.Fatalf("got %d activities, %d samples", len(acts), len(samples))
}
walk := acts[0]
if walk.Kind != "walk" || walk.ExternalID != "W1" || walk.EndedAt.Sub(walk.StartedAt) != 45*time.Minute {
t.Errorf("walk: %+v", walk)
}
if walk.StartedAt.Hour() != 14 { // 07:00 -0700 is 14:00 UTC
t.Errorf("start not converted to UTC: %v", walk.StartedAt)
}
if acts[1].Kind != "sleep" || samples[0].Value != 812 {
t.Errorf("sleep %+v, sample %+v", acts[1], samples[0])
}
}