Commit Graph

10 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
ee24ab8aeb feat: implement Phase 3 CLI Polish - Error handling, output formatting, completions
Implements comprehensive CLI improvements for Hatch:

Error Handling:
- Add structured CLIError type with exit codes
- Add consistent exit codes (OK, GeneralError, UsageError, NetworkError, ServerError, ConfigError)
- Add colored error messages with details
- Add proper connection refused error handling

Output Formatting:
- Add ANSI color support with terminal detection
- Add colored success/error/warning messages
- Add compact output format option
- Add --output flag for json/table/compact formats

Shell Completions:
- Add bash completions with full command/flag support
- Add zsh completions with descriptions and subcommand handling
- Add fish completions with helper functions
- Add PowerShell completions with native argument completer
- Add hatch completions <shell> command

Configuration Support:
- Add config file support (XDG_CONFIG_HOME or ~/.config/hatch/config.json)
- Add environment variable overrides (HATCH_URL, HATCH_FORMAT, NO_COLOR)
- Add hatch config show/set/get/init commands
- Add configuration keys: server_url, format, no_color, timeout

Additional Improvements:
- Add version command with build-time version injection
- Add help command with colored usage output
- Add --output flag to all commands for format control
- Add request timeout support
- Improve error messages with actionable suggestions
- Add comprehensive test coverage

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-24 05:17:58 +02:00
Riley Zhang
1959846581 Merge branch 'cto/ELF-169-cli-documentation' into engineer/ELF-185-phase1-foundation 2026-06-24 05:11:02 +02:00
Riley Zhang
22295e4cd1 test: add integration tests for CLI package
- Added TestServerConfigurations for server setup verification
- Added TestMultipleEndpointsConcurrency for concurrent access testing
- Added TestErrorHandling for error scenarios (invalid JSON, missing endpoints, invalid replay IDs)

These tests verify the CLI server behavior through integration testing
rather than unit testing the main function directly.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-24 05:09:13 +02:00
SoftwareEngineer
60e25bfc9d feat: add thin CLI for Hatch
Implements CLI commands that wrap the JSON API layer:
- hatch capture <url> - Send request to endpoint and store it
- hatch inspect <endpoint> - Fetch requests as JSON
- hatch search <endpoint> - Search captured traffic
- hatch replay <request-id> - Replay a captured request
- hatch mock set <endpoint> - Configure mock response
- hatch doc generate <endpoint> - Output OpenAPI spec

Uses stdlib flag package for CLI parsing (boring tools philosophy).
All commands talk to running Hatch server via HTTP.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-23 09:59:38 +02:00
SoftwareEngineer
027e9a4a49 Add E2E smoke test — one-command DoD gate (ELF-23 Task 8)
TestSmokeE2E starts a real server and exercises the full product flow:
- Phase 1: Health check (liveness probe)
- Phase 2: Capture all 5 HTTP methods, verify stored
- Phase 3: Inspect page renders HTML with request cards, replay UI, SSE script
- Phase 4: SSE stream receives live events on capture
- Phase 5: Mock configuration and response (set mock → capture returns mock)
- Phase 6: Replay a captured request to a sink server
- Phase 7: Edge cases (query params, binary body, SSRF protection)

The one-command gate: go test ./cmd/hatch -run TestSmokeE2E -v

Also fix .gitignore: the bare 'hatch' entry was matching cmd/hatch/
directory, preventing test files from being tracked. Narrowed to /hatch
(root binary only) and hatch.exe.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-22 19:22:56 +02:00
SoftwareEngineer
7668661f74 Add mock handler tests and fix env leakage in main_test.go
- Added TestMockSetsAndConfiguresResponse: verifies PUT /e/{id}/mock stores mock config
- Added TestMockReturnsConfiguredResponseOnCapture: verifies capture returns mock response
  when one is configured, and the request is still recorded
- Added TestMockAutoCreatesEndpointOnSet: verifies mock endpoint auto-creates if missing
- Fixed TestHealthzSmoke to use t.Setenv instead of os.Setenv to prevent env leak

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-22 19:13:12 +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
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
SoftwareEngineer
bc881dcebb feat: foundation Go module, HTTP server, Docker packaging
- Go module (github.com/elfoundation/hatch) with go 1.25
- cmd/hatch: HTTP server with GET /healthz returning 200 OK
- Multi-stage Dockerfile producing static binary from scratch
- docker-compose with hatch + optional Caddy reverse proxy
- CI placeholder with Go test/lint stubs
- .gitignore, .dockerignore, .env.example

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