Commit Graph

6 Commits

Author SHA1 Message Date
Riley Zhang
12775f836c Phase 4: Production readiness - graceful shutdown, health checks, load testing, pprof
- Graceful shutdown: SIGINT/SIGTERM handling with 5s timeout
- Readiness probe (/readyz): pings database before reporting ready
- Connection pool: documented MaxOpenConns(1) for SQLite single-writer constraint
- Load test tool: cmd/loadtest with configurable concurrency/total requests
- Shell script: scripts/load-test.sh for quick load testing
- pprof endpoints: /debug/pprof/* when HATCH_DEBUG env var is set

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-24 05:26:42 +02:00
Riley Zhang
ceaf7f9fb5 test: add unit tests for handler and store packages
- Added TestSearchRequests for store package (0% → 100% coverage)
- Added TestOpenInMemory for store package Open function
- Added TestNewSQLiteRepoNilDB for error handling
- Added TestV1ReplayRequest for handler package (0% → 100% coverage)
- Added TestPrettyJSON and TestFormatTime for inspect helpers
- Added TestJoinPath for path joining utility
- Added TestHandleMockReturnsErrorOnInvalidJSON
- Added TestInspectReturnsHTMLErrorOnRepoFailure
- Added TestCaptureMissingEndpointID, TestV1CaptureRequestMissingEndpoint, TestV1ListRequestsMissingEndpoint

Coverage improvements:
- Handler: 77.1% → 82.2%
- Store: 61.1% → 82.2%

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-24 05:07:50 +02:00
SoftwareEngineer
dc0394cada Implement JSON API layer for Hatch (ELF-160)
Add v1 JSON API endpoints alongside existing HTML endpoints:

- POST /v1/endpoints/{id}/requests: Capture JSON request
- GET /v1/endpoints/{id}/requests: List or search requests
- POST /v1/endpoints/{id}/requests/{reqId}/replay: Replay captured request
- PUT /v1/endpoints/{id}/mock: Set mock configuration
- GET /v1/endpoints/{id}/openapi.json: OpenAPI 3.1 specification

Add SearchRequests to Repository interface and implement simple LIKE search.
Write integration tests for all v1 endpoints. Ensure backward compatibility
with existing HTML endpoints.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-23 09:53:13 +02:00
SoftwareEngineer
4256d34c27 feat: add one-click replay for captured requests
- Add POST /e/{endpoint}/requests/{id}/replay endpoint
- Replay re-sends captured method, path, headers, query, body to target URL
- Response includes target status code, headers, body (truncated 64KB)
- SSRF guard: denies replay to private/loopback by default
- Opt-in env var HATCH_ALLOW_PRIVATE_REPLAY=true for local dev
- Server-rendered inspect page at GET /e/{endpoint} with replay button UI
- SSE live stream for new requests (EventSource)
- Mock configuration at PUT /e/{endpoint}/mock
- Store: GetRequest, GetMock, SetMock methods added
- Chi router migration from stdlib ServeMux
- 26 passing tests including replay unit tests and E2E capture-to-replay

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-22 16:58:42 +02:00
SoftwareEngineer
5bbf995f32 Fix capture: endpoint ID/URL mismatch, routing, and extractID
- Use URL as endpoint ID so handler path-segment lookups resolve correctly.
  Previously CreateEndpoint generated a random UUID for the ID, but the
  handler always queries by the path segment — every GetEndpoint call
  missed, causing duplicate UNIQUE violations on subsequent requests
  and orphaned request records (endpoint_id mismatch).

- Register both /{endpoint} and /{endpoint}/ patterns so bare and
  nested capture paths both route to the handler (Go 1.22+ ServeMux).

- Strip query string in extractID for robustness, even though the
  library never sends ? in r.URL.Path.

- Remove unused net/http import from handler_test.go (caught by vet).

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-22 14:38:50 +02:00
CTO
90c3f6285d feat: mock endpoint — configure response per endpoint
- Add mock_status, mock_headers, mock_body columns to endpoints schema
- Add MockConfig struct and UpsertMock to Repository interface
- Implement UpsertMock in sqliteRepo (INSERT ON CONFLICT UPDATE)
- Update GetEndpoint to return mock configuration when present
- Add PUT /e/{endpoint_id}/mock handler with JSON body {status, headers, body}
- Add catch-all /{endpoint_id} handler returning mock or default 200
- Header sanitization: only allow Content-Type, Cache-Control, X-*
- Wire handler into cmd/hatch main with SQLite store
- Fix Dockerfile: COPY go.sum for reproducible builds
- Tests: store mock CRUD, handler mock config + header sanitization

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-22 14:32:53 +02:00