fix: allow clearing logs without request body#2813
Conversation
|
Hi @thedotmack, I accidentally closed the previous PR #2675 due to a misoperation. This is the new PR replicating the exact changes. Please let me know when you have time to review and merge this. Thanks! |
Greptile SummaryThis PR fixes the
Confidence Score: 5/5Safe to merge — the change is a targeted middleware removal on a single non-destructive endpoint, backed by new regression tests. The fix is a one-line route registration change (drop a validation middleware that was rejecting valid bodyless requests). The handler itself is unchanged, the audit log entry is preserved, and two new tests directly exercise the repaired path. No other routes or shared logic are touched. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Viewer as Viewer UI
participant Express as Express App
participant VB as validateBody middleware (removed)
participant Handler as handleClearLogs
Note over Viewer,Handler: Before this PR (broken path)
Viewer->>Express: POST /api/logs/clear (no body)
Express->>VB: "req.body === undefined"
VB-->>Viewer: 400 Bad Request
Note over Viewer,Handler: After this PR (fixed path)
Viewer->>Express: POST /api/logs/clear (no body)
Express->>Handler: req (body ignored)
Handler->>Handler: writeFileSync(logFile, '')
Handler->>Handler: logger.info(Log file cleared via UI)
Handler-->>Viewer: "200 { success: true, message: Log file cleared }"
Reviews (2): Last reviewed commit: "fix: allow clearing logs without request..." | Re-trigger Greptile |
e19bad2 to
e8982e1
Compare
Summary
POST /api/logs/clearto run without a request body, matching the viewer's clear request.Log file cleared via UIaudit log entry after a successful clear.Reproduction
Before this change, the viewer showed
Failed to clear logs: Bad Requestand the log file was not truncated.Root Cause
The viewer calls
authFetch('/api/logs/clear', { method: 'POST' })without a body. The route previously wrapped the handler invalidateBody(z.object({}).passthrough()), soreq.body === undefinedfailed validation and returned400 Bad Requestbefore the log file was truncated.Expected Behavior
The bodyless clear request should return success and remove the previous log contents. The route still records the existing
Log file cleared via UIaudit entry after a successful clear.Validation
bun test tests/services/logs-routes-tail-read.test.tsThis replaces #2674 with a narrower patch focused only on the bodyless clear request.