Fix location races, run database tests in CI, add make check
Test and publish / test (push) Has been cancelled
Test and publish / publish (push) Has been cancelled

Location: a leave decided its destination before taking the device lock,
so a "leave home" racing an "arrive gym" could undo the arrival. The
decision (now ingest.Destination) runs inside MoveTo under the lock.
Transition external IDs were device|label|time, which collided (500) when
out-of-order events were clamped to the same start; they now name the
interval being closed.

hypr-agent: a control command arriving during shutdown no longer blocks
its goroutine forever.

Tests: internal/testdb gives each database test its own throwaway
database, so they run in parallel and no longer truncate the dev data.
New store tests cover both location bugs. CI starts a Postgres container
so these tests actually run, and adds gofmt, staticcheck (pinned as a go
tool) and -race. `make check` runs the same locally.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-14 22:48:41 +01:00
co-authored by Claude Opus 5.5
parent 0be97384fa
commit cfe17ecf5d
13 changed files with 285 additions and 80 deletions
+4 -24
View File
@@ -7,40 +7,20 @@ import (
"log/slog"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"time"
"github.com/jackc/pgx/v5/pgxpool"
"ccp/internal/auth"
"ccp/internal/migrations"
"ccp/internal/store"
"ccp/internal/testdb"
)
// Requires a disposable database, e.g. the one from deploy/docker-compose.yml:
//
// TEST_DATABASE_URL=postgres://tracker:tracker@localhost:5432/tracker go test ./internal/api
// Needs TEST_DATABASE_URL; see internal/testdb.
func setup(t *testing.T) (*httptest.Server, string) {
url := os.Getenv("TEST_DATABASE_URL")
if url == "" {
t.Skip("TEST_DATABASE_URL not set")
}
t.Parallel()
ctx := context.Background()
pool, err := pgxpool.New(ctx, url)
if err != nil {
t.Fatal(err)
}
t.Cleanup(pool.Close)
if err := migrations.Up(ctx, pool); err != nil {
t.Fatal(err)
}
if _, err := pool.Exec(ctx, `TRUNCATE activities, samples, goals, devices RESTART IDENTITY`); err != nil {
t.Fatal(err)
}
st := store.New(pool)
st := store.New(testdb.New(t))
_, key, err := st.CreateDevice(ctx, "test", "hyprland")
if err != nil {
t.Fatal(err)