Skip to main content

Testing

Testing in Moveat is used to protect business correctness, not only to increase a coverage number. The highest-risk bugs are not visual. They are product-state bugs: duplicated meals, wrong calorie summaries, broken sessions, incorrect unit conversion, webhook retries that write twice, or Agent actions that bypass Platform validation.
Coverage numbers below were measured on 2026-06-13 from the local repositories.

Current snapshot

Platform

21 test files, 61 passing tests. Coverage exists but currently fails the configured 80% global threshold.

Agent

Go tests pass. Statement coverage is 59.5% and no global coverage threshold is enforced yet.
Platform’s regular test suite passes, but yarn test:coverage fails because the repository is configured with an 80% global threshold and current coverage is below that threshold.

Testing philosophy

Moveat should prioritize tests in this order:
  1. Business invariants that can corrupt user data.
  2. Auth and authorization boundaries.
  3. Agent-to-Platform contract behavior.
  4. Unit conversion and time-zone handling.
  5. External integration adapters.
  6. Low-risk wiring and static helpers.
Coverage is useful, but it should not drive shallow tests. A lower coverage module with strong tests around its dangerous paths can be safer than a high-coverage module that only tests happy paths.

Platform testing

Platform uses Vitest for TypeScript tests.

Commands

yarn verify runs linting, typecheck, tests and build.

Coverage result

What Platform already tests

Main Platform gaps

Meal idempotency

Replaying the same idempotency key should return the same entry and must not increment summaries twice.

Webhook race safety

Concurrent duplicate writes should safely handle unique conflicts and preserve exactly-once summary increments.

Onboarding gates

Meal, weight and workout actions that require profile context should fail cleanly when onboarding is incomplete.

Weight display contract

Latest and list responses should preserve the response-level unitSystem wrapper and server-side conversion.

Workout persistence

Workout sessions should test exercises, sets, invalid payloads and future idempotency behavior.

Session guard

Missing, expired and malformed sessions should return predictable unauthorized errors.

Agent testing

Agent uses the standard Go test runner.

Commands

The Makefile sets GOCACHE and GOMODCACHE to /tmp so local runs do not depend on user-level cache directories.

Package-level coverage

What Agent already tests

Main Agent gaps

  1. Platform client attaches internal auth token, timeout, correlation ID and idempotency key.
  2. Platform client maps non-2xx responses into typed errors.
  3. Channel resolution caches safely but never becomes source of truth.
  4. Register meal flow derives idempotency from the WhatsApp message ID.
  5. LLM parser handles incomplete, malformed and partially valid JSON.
  6. Media download validates MIME type and handles Meta API failures.
  7. Startup fails fast when required LLM or Platform configuration is missing.

Deploy readiness policy

Before deploying Platform:
Before deploying Agent:
Before deploying a contract change between Agent and Platform:
  1. Platform tests pass.
  2. Agent tests pass.
  3. Swagger/OpenAPI reflects the Platform contract.
  4. Agent DTO/client code matches the internal API contract.
  5. Idempotency and auth behavior are manually verified in a local or staging-like environment.
  6. Grafana dashboards are ready to inspect errors after deploy.

Coverage target recommendation

Platform already has an 80% threshold. The practical next step is not lowering it; it is adding tests for the modules that represent real product risk. Agent should eventually add a coverage target, but only after excluding low-value command/dev-tool packages from the aggregate or separating them from product packages. Otherwise the number will encourage testing the wrong code.