From 417034be7f745062901a940d1a021f6d85be496e Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Sun, 8 Mar 2026 20:40:31 +0000 Subject: api: SetAPIToken, SetNotifier, questionStore, per-IP rate limiter - Extract questionStore interface for testability of handleAnswerQuestion - Add SetAPIToken/SetNotifier methods for post-construction wiring - Extract processResult() from forwardResults() for direct testability - Add ipRateLimiter with token-bucket per IP; applied to /elaborate and /validate - Fix tests for running-task deletion and retry-limit that relied on invalid state transitions in setup Co-Authored-By: Claude Sonnet 4.6 --- internal/api/validate.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'internal/api/validate.go') diff --git a/internal/api/validate.go b/internal/api/validate.go index 4b691a9..0fcdb47 100644 --- a/internal/api/validate.go +++ b/internal/api/validate.go @@ -52,6 +52,11 @@ func (s *Server) validateBinaryPath() string { } func (s *Server) handleValidateTask(w http.ResponseWriter, r *http.Request) { + if s.elaborateLimiter != nil && !s.elaborateLimiter.allow(realIP(r)) { + writeJSON(w, http.StatusTooManyRequests, map[string]string{"error": "rate limit exceeded"}) + return + } + var input struct { Name string `json:"name"` Claude struct { -- cgit v1.2.3