Skip to content

Fix panic in test mock handlers with safe type assertions#309

Merged
lpcox merged 2 commits into
mainfrom
copilot/fix-test-handlers-unsafe-assertions
Jan 17, 2026
Merged

Fix panic in test mock handlers with safe type assertions#309
lpcox merged 2 commits into
mainfrom
copilot/fix-test-handlers-unsafe-assertions

Conversation

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

Test mock HTTP handlers were panicking on nil type assertions when handling requests without method fields (e.g., SSE heartbeats, connection probes).

Changes

TestCallBackendTool_ReturnsNonNilCallToolResult handler:

  • Replace require.NoError(err) with error check + HTTP 400 response (line 32)
  • Add safe type assertion for method field (line 37-40)

TestCallBackendTool_ErrorStillReturnsCallToolResult handler:

  • Add JSON decode error handling with HTTP 400 response (line 157-161)
  • Replace unsafe method := req["method"].(string) with safe check (line 163-167)

Before

var req map[string]interface{}
err := json.NewDecoder(r.Body).Decode(&req)
require.NoError(err)  // ❌ Fails test on EOF

method := req["method"].(string)  // ❌ Panics if nil

After

var req map[string]interface{}
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
    w.WriteHeader(http.StatusBadRequest)
    return
}

method, ok := req["method"].(string)
if !ok {
    w.WriteHeader(http.StatusBadRequest)
    return
}

Both handlers now gracefully reject invalid requests instead of panicking or failing the test.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…handling

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unsafe type assertions in test mock handlers Fix panic in test mock handlers with safe type assertions Jan 17, 2026
Copilot AI requested a review from lpcox January 17, 2026 00:13
@lpcox lpcox marked this pull request as ready for review January 17, 2026 00:17
@lpcox lpcox merged commit 082e59a into main Jan 17, 2026
3 checks passed
@lpcox lpcox deleted the copilot/fix-test-handlers-unsafe-assertions branch January 17, 2026 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants