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
+29 -7
View File
@@ -8,9 +8,10 @@
# the host).
#
# TWO JOBS
# test go vet + go test, as `make test`. The API tests skip themselves
# here: they need TEST_DATABASE_URL, and CI has no Postgres. Then
# the Vue app's typecheck and build, in a node container.
# test gofmt, go vet, staticcheck and go test (with -race, and the
# database tests against a throwaway Postgres container), as
# `make check`. Then the Vue app's typecheck and build, in a node
# container.
# publish main only, after test: builds deploy/Dockerfile, pushes it to
# this Gitea's container registry as :<sha> and :latest, then
# pulls it into the web_server stack (its `activity-tracker`
@@ -51,9 +52,25 @@ jobs:
git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC"
test -f "$SRC/go.mod"
# A throwaway Postgres on its own network, for the database tests
# (internal/testdb gives each test its own database on it).
- name: Start Postgres
shell: bash
run: |
set -eu
docker network create "ci-$SHA"
docker run -d --name "ci-pg-$SHA" --network "ci-$SHA" --network-alias pg \
-e POSTGRES_PASSWORD=ci postgres:17
for i in $(seq 1 30); do
docker exec "ci-pg-$SHA" pg_isready -U postgres -h localhost && exit 0
sleep 1
done
docker logs "ci-pg-$SHA"
exit 1
# Read-only source, and named volumes for the module and build
# caches so repeat runs don't download everything again.
- name: Go - vet and test
- name: Go - lint and test
shell: bash
run: |
set -eu
@@ -61,8 +78,10 @@ jobs:
-v "$SRC":/src:ro -w /src \
-v activity_tracker_ci_gomod:/go/pkg/mod \
-v activity_tracker_ci_gobuild:/root/.cache/go-build \
--network "ci-$SHA" \
-e TEST_DATABASE_URL='postgres://postgres:ci@pg:5432/postgres?sslmode=disable' \
golang:1.27 \
sh -c 'go vet ./... && go test ./...'
sh -c 'test -z "$(gofmt -l .)" && go vet ./... && go tool staticcheck ./... && go test -race -count=1 ./...'
# Copies web/ out of the read-only source so node_modules and the
# build output stay in the container.
@@ -76,10 +95,13 @@ jobs:
node:24-alpine \
sh -c 'cp -r /src/web /web && cd /web && npm ci && npm run typecheck && npx vite build --outDir /tmp/dist'
- name: Remove the scratch directory
- name: Remove the scratch directory and Postgres
if: always()
shell: bash
run: rm -rf "$SRC"
run: |
rm -rf "$SRC"
docker rm -f "ci-pg-$SHA" || true
docker network rm "ci-$SHA" || true
publish:
needs: test