---
name: Fix Collect Coverage Button Error
---

# Bug 47: Fix Collect Coverage Button Error

## Description

Pressing "Collect Coverage" in the workflow gates UI produces a giant stack trace. The API endpoint `POST /workflow/coverage/collect` (`server/src/http/workflow.rs:430`) runs `pnpm run test:coverage` and when it fails, dumps the entire stderr into the error response (line 455). The frontend then renders this raw error.

## Root Cause

`collect_coverage` in `workflow.rs` returns the full stderr from the failed `pnpm run test:coverage` command as a `bad_request` error. No truncation or sanitization.

## How to Reproduce

```bash
curl -s http://localhost:3001/api/workflow/coverage/collect \
  -H 'Content-Type: application/json' \
  -d '{"story_id":"any_story","threshold_percent":80}' | python3 -m json.tool
```

**Actual result:** A giant JSON error response containing the full stderr output from `pnpm run test:coverage` — hundreds of lines of stack traces.

**Expected result:** A short, human-readable error message, e.g. `{"error": "Coverage not configured: no test:coverage script found in frontend/package.json"}` — or if the command exists but fails, a truncated summary (first 500 chars max).

## Acceptance Criteria

- [ ] `collect_coverage` API truncates/sanitizes error output before returning it (e.g. first 500 chars max)
- [ ] Frontend `GatePanel` renders coverage errors in a contained, non-overflowing way
- [ ] If `test:coverage` script doesn't exist in `package.json`, return a clear "coverage not configured" message instead of running the command
