test: add coverage for agents API, agent service, task-run repo, meeting analytics, and SSE health payload#28
Merged
Conversation
…ing analytics, and SSE health payload - Export buildSystemPrompt and buildUserPrompt from agentService.ts as pure helpers for direct testing - Add makeTestAgent and makeTestMeeting factory helpers to test-utils.ts - New: __tests__/integration/agents-api.test.ts — 8 tests covering GET/POST /api/agents (happy path, validation errors, 404 on missing project) - New: __tests__/unit/task-run-repo.test.ts — 14 tests for dbGetTaskRunsByAgent and dbGetRecentTaskRunsByAgent (filtering, isolation, boundary conditions, shape validation) - New: __tests__/unit/meeting-analytics.test.ts — 7 tests for dbGetMeetingAnalytics (empty project, token/cost sums, daily grouping, status filter, project isolation, date range, null handling) - New: __tests__/unit/agent-service.test.ts — 13 tests for buildSystemPrompt, buildUserPrompt, and the double-scheduling guard in assignAgentToTask - New: __tests__/integration/stream-health-payload.test.ts — 5 tests verifying agentHealth map shape, per-agent entry presence, and hasEnoughData flag for sparse vs. rich agents Total: 213 tests (161 → +52), all passing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
buildSystemPromptandbuildUserPromptfromagentService.tsas testable pure helpers (no behaviour change)makeTestAgentandmakeTestMeetingfactory helpers to__tests__/helpers/test-utils.ts__tests__/integration/agents-api.test.ts/api/agents— happy paths, validation (missing fields, invalid type enum), 404 on non-existent project__tests__/unit/task-run-repo.test.tsdbGetTaskRunsByAgent(filtering, isolation, ordering, shape) +dbGetRecentTaskRunsByAgent(time boundary, empty window, boundary-inclusive, cross-agent isolation)__tests__/unit/meeting-analytics.test.tsdbGetMeetingAnalytics— empty project, token/cost aggregation, daily grouping,concluded-only filter, project isolation, date range, null-field handling__tests__/unit/agent-service.test.tsbuildSystemPrompt(role-specific content, distinctness),buildUserPrompt(context injection, directory, role-specific sections), double-scheduling guard inassignAgentToTask__tests__/integration/stream-health-payload.test.tsgetStreamPayload().agentHealth— key presence, per-agent entry,AgentHealthMetricsshape,hasEnoughData: falsefor sparse agents,hasEnoughData: truewith populated metrics for rich agentsResult: 161 → 213 tests, all passing. Zero new type errors.
Design decisions
buildSystemPrompt/buildUserPromptare exported withexport function— smallest possible surface-area change to make pure logic directly testable.makeTestMeetingmessages usemeeting.id(post-spread) formeetingIdFK, not the pre-spread local variable — avoids FK constraint failures when callers pass anidoverride.seedMeetingin the meeting analytics test callsdbUpdateMeetingMessageafterdbAddMeetingMessagefor token/cost fields — mirroring how production code sets stats after streaming completes.Date.now()(not a fixed past date) so runs always fall within the 7-day rolling window regardless of when the suite runs.Test plan
npm run test:run— 213/213 passingnpm run type-check— no new errors (5 pre-existing errors unchanged)🤖 Generated with Claude Code