LLM experiment 01: asking Claude Code to fix #211 #215
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Issue #211 was a fairly simple bug fixed in #212 (and with follow-up tests unfortunately spread across #213 and #214 because of, well, sloppiness on my part).
I thought it might be an interesting experiment to try Claude Code, so I fed it this prompt and nothing else:
I'm just opening this pull request to record the results and maybe some thoughts on them, mostly for my future self. I may repeat this experiment again in the future. This will not be merged.
Results
My own fix (again, unfortunately a bit hard to see because it ended up spread across 3 distinct pull requests/commits) for the issue looks like this:
diff for my own fix
Claude Code took a slightly different and more general approach:
diff for Claude Code's fix
Some scattered thoughts
In the context of testing Go HTTP servers in general (and
go-httpbinspecifically, due to its edge-case-y nature), I prefer writing tests using real live TCP connections to real live (but ephemeral) HTTP servers managed by the stdlib's httptest package (which is one of my single favorite golang features).The existing table-driven tests for this
/iphandler, however, are an exception in go-httpbin's test suite, as noted in this comment:go-httpbin/httpbin/handlers_test.go
Lines 391 to 395 in 5154c22
In my own fix I noticed that context and decided to add a separate subtest that actually does use a real TCP connection to a real server exactly because it would better simulate real world requests and exercise the fix in question, leading to a smaller change that — to me — more realistically tests the fix.
Claude's fix instead extends the existing table-driven tests to explicitly control the exact data seen by the updated helper function. That's valid, but, to me, a bit less valuable when there are better alternatives!
I suppose I could teach Claude Code (or whatever) about this preference via a
CLAUDE.mddoc in the root of the repo that explicitly instructs it to prefer "real" HTTP server tests where possible?Claude's fix is in some ways more thorough than mine, treating every possible "source" of client IP addresses (basically a variety of platform-specific headers) as a potential source for client IPs containing port numbers, where I know (or … at least I think I know) that those platform-specific headers will never contain port numbers. Maybe Claude's fix is the right one, Postel's law and all?
View the whole Claude Code transcript here. It is fairly cool to watch it work.
This fix cost me $1.05 and took Claude ~3.5 minutes, according to the cost summary:
That honestly seems pretty expensive to me, in part because I just read this comment from Simon Willison about LLM costs:
