test(service): add vitest coverage for ingest, routing, render, crons#4
Merged
Conversation
Expands the existing tests/ suite from 64 → 127 tests across 6 new files, covering the gaps called out in the test plan: - ingest-validate: every event type round-trips with the correct default category; missing/invalid required fields are rejected - ingest-pipeline: channel + webhook destinations, skipped/failed status, digest path does not invoke any transport - routing-pickroute: webhook URL targets, unknown category fall-through, order-independent most-specific-wins - render-types: per-event-type baseline snapshots + severity overrides on infra + links/footerNote primitives + to-do/remind action_id identity - digest-group: pure grouping helper extracted from app/api/cron/digest (lib/digest/group.ts) so the bucketing logic is testable in isolation - cron-digest: route-level auth, empty-pending short-circuit, multi-category grouped fan-out - cron-reminders: route-level auth, empty-due short-circuit, per-reminder post + mark-sent, no status flip on transport failure Mocks @/lib/db and @/lib/slack/transport at the vitest module boundary — no Postgres, no Slack API. Also adds .github/workflows/test-service.yml (sibling to test-client.yml) scoped to app/**, lib/**, tests/**, and root config files. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Deployment failed with the following error: Learn More: https://vercel.link/3Fpeeb1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expands the service-side vitest suite from 64 → 127 tests across 6 new files, covering the gaps in event validation, ingest pipeline, routing precedence, render house style, and cron handlers.
What changed
New tests (
tests/)tests/ingest-validate.test.tsgeneric/raware rejected. Explicit category override beats the type default.tests/ingest-pipeline.test.tsingestEventposts to a channel destination, posts to a webhook destination, recordsskippedwhen no route resolves, recordsfailedon transport error, and bypasses the transport entirely ondigest:trueinfo events.tests/routing-pickroute.test.tsnullreturned when only other-project rules exist.tests/render-types.test.tsinfraseverity override (info → 📡, warning → 📡, error → 🔴).linksadd URL buttons.footerNoterenders as a context line.actions: ['todo']→add_todo.actions: ['remind']→remind_1h+remind_24h.tests/digest-group.test.tsgroupPendingForDigestreturns[]for empty input, creates one group per(projectId, category), treatsnullprojectId as its own bucket.digestLineForpayload-field preference order: title → message → name → email → type.tests/cron-digest.test.tsGET /api/cron/digestreturns 401 without bearer,{ ok: true, groups: 0, posted: 0 }for empty pending, and groups multi-category events into 2 posts to the resolved channel.tests/cron-reminders.test.tsGET /api/cron/remindersreturns 401 without bearer,{ due: 0, sent: 0 }when nothing due, posts each due reminder (threading viamessageTswhen present) and flips status tosent, and does NOT flip status when the transport returnsok: false.Production refactor (minimal, testability-only)
lib/digest/group.ts(new) — extracts the pure(projectId, category)grouping logic +digestLineForfromapp/api/cron/digest/route.ts. The route now imports them. Behaviour unchanged.CI
.github/workflows/test-service.yml(new) — sibling totest-client.yml. Triggers on PRs /mainpushes touchingapp/**,lib/**,tests/**,vitest.config.ts,vercel.json,package.json,pnpm-lock.yaml. Runspnpm test. Does not overlap with the client workflow'spackages/client/**scope.Mocking decisions
@/lib/dbmocked at the vitest module boundary — each test stubs theselect / insert / updatechain it actually exercises. Where the route handler awaits awhere(...)result, the stub returns a thenable.@/lib/slack/transport(postToChannel/postToWebhook) mocked so no test hits the Slack API.@/lib/routing.resolveDestinationmocked from the ingest tests so route precedence is exercised separately in pure-function tests againstpickRoute.vitest.config.tsDATABASE_URLdummy stays in place — postgres-js is lazy and the mocks intercept before any query is issued.Verification
pnpm test→ 16 files, 127 tests pass (0.7s).npx tsc --noEmitclean.pnpm lintclean.Out of scope (intentionally)
packages/client/**— already covered bytest-client.yml. Untouched.🤖 Generated with Claude Code