Skip to content

OSS hardening + Trends page & weekly digest - #2

Merged
8tp merged 2 commits into
mainfrom
chore/ci-tests-seed-fix
Jun 23, 2026
Merged

OSS hardening + Trends page & weekly digest#2
8tp merged 2 commits into
mainfrom
chore/ci-tests-seed-fix

Conversation

@8tp

@8tp 8tp commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Two slices of "what's next for Vitals": a quality gate the public repo was missing, and the first net-new feature.

① OSS hardening

  • Test suite (tests/, 20 tests). Built-in node:test + the tsx the repo already runs on — no new dependencies, resolution matches production.
    • confidence.test.ts — SPEC confidence rules + accuracy-weight decay
    • consensus.test.tsnormalizeAndUpsert against a real throwaway SQLite DB (single→MEDIUM, two-source weighted mean→HIGH, 0h-sleep exclusion, "missing device ≠ anomaly")
    • seed.test.ts — proves the README's deterministic-seed claim
    • weekly.test.ts — week-over-week digest math
  • CI (.github/workflows/ci.yml). Gates typecheck + lint + test + build on PRs + pushes to main, Node 20 & 22.
  • Bug fix — fresh-DB seed crash. npm run db:seed crashed on a brand-new DB (FOREIGN KEY constraint failed): sleep_sessions/workouts FK daily_summary(date), but the seed upserted children before normalizeAndUpsert made the parent rows. Broke the QUICKSTART "5-minute fresh start". Fixed with a parent-row stub at the top of the day loop.
  • Lint clean. 1 error + 4 warnings → 0.

② Consensus framing

Decision: keep it. The multi-source re-add revived it; with Fitbit + Apple it genuinely reconciles two sources. Now test-covered. No code change.

③ Trends page + weekly digest

  • /trends (new 6th nav tab): "this week vs last" digest cards + per-metric 30-day consensus sparklines, built from existing PageHeader/Sparkline/TrendIndicator (matches DESIGN.md).
  • computeWeeklySummary + GET /api/insights/weekly — deterministic trailing-7d vs prior-7d averages for HRV/RHR/sleep + best/shortest night. No AI provider needed; computed on demand.
  • Replaces the weekly-report.ts stub ("Phase 3 fills this in…") with the real computation.

Verification

typecheck + lint + test + build green locally and in CI on Node 20 & 22. Weekly + vitals endpoints verified end-to-end over HTTP against a seeded DB (weekly: 7 days/3 metrics/best-night; vitals: 25 consensus points + delta).

🤖 Generated with Claude Code

8tp and others added 2 commits June 22, 2026 15:55
Quality hardening for the public repo:

- tests/: 17-test suite via built-in node:test + tsx (no new deps, resolution
  matches production). Covers confidence rules, the weighted-consensus
  normalizer against a real throwaway SQLite DB, and seed determinism.
- .github/workflows/ci.yml: gates typecheck + lint + test + build on PRs and
  pushes to main, across Node 20 & 22 (honors engines).
- Fix: `npm run db:seed` crashed on a fresh DB with a FOREIGN KEY failure —
  sleep_sessions/workouts FK daily_summary(date), but children were upserted
  before normalizeAndUpsert created the parent rows. Insert a parent stub at
  the top of the day loop; the normalizer fills real values via ON CONFLICT.
  This restores the QUICKSTART "5-minute fresh start".
- Lint: 1 error + 4 warnings -> 0 (prefer-const, unused import, inline
  import() type annotations).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a sixth nav surface and the weekly digest the weekly-report stub
promised.

Backend:
- services/weekly.ts: computeWeeklySummary — trailing-7-day averages of each
  consensus metric (HRV, RHR, sleep) vs the prior 7 days, with direction +
  good/bad tone and best/shortest sleep night. Pure read + arithmetic, no AI
  provider needed.
- GET /api/insights/weekly: computes on demand so the page renders even before
  the weekly cron runs.
- weekly-report.ts: replace the placeholder stub with the real computation,
  stored as a markdown digest + structured snapshot.
- shared: WeeklyMetric / WeeklySummary types.

Frontend:
- pages/TrendsPage.tsx at /trends: "this week vs last" digest cards
  (TrendIndicator) + per-metric 30-day consensus sparklines off the existing
  /api/vitals endpoint. Built from existing PageHeader/Sparkline/Metric so it
  matches DESIGN.md.
- IconTrends + nav entry + route.

Tests: tests/weekly.test.ts (3) — week-over-week deltas, empty-week nulls,
best/shortest night. Suite now 20 tests. Verified end-to-end over HTTP.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@8tp 8tp changed the title ci: test suite + CI gate; fix fresh-DB seed crash OSS hardening + Trends page & weekly digest Jun 22, 2026
@8tp
8tp merged commit d27e696 into main Jun 23, 2026
2 checks passed
@8tp
8tp deleted the chore/ci-tests-seed-fix branch June 23, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant