Accept JSON-array profiles, not just object streams#10
Merged
Conversation
A profile was only loadable as a bare stream of concatenated JSON Call
objects. An agent (or human) authoring a "list of weighted calls" reaches
for the obvious JSON array `[{...},{...}]` first, which failed with the
cryptic `cannot unmarshal array into Go value of type profile.Call`.
LoadFromReader now peeks the first JSON token and accepts either form
interchangeably: a top-level array or the legacy object stream. The file
loader inherits this for free. Field names remain case-insensitive, so the
lowercase keys agents tend to emit also load.
Docs updated to present the array as the primary shape; tests cover the
array, single-element array, lowercase keys, empty array, malformed array,
and the file path.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Using hammer as an agent surfaced one clear "used it wrong" footgun: the
profile loader only accepted a bare stream of concatenated JSON
Callobjects. The obvious shape an agent emits for "a list of weighted calls" is
a JSON array — and that failed:
The README even had to caveat the format with "(no enclosing array — just
concatenate them)", a tell that everyone reaches for the array first.
Change
profile.LoadFromReadernow peeks the first JSON token and accepts eitherform interchangeably:
[ {…}, {…} ](now the documented primary shape){…} {…}(still works, unchanged)LoadFromFileinherits this for free. JSON field names stay case-insensitive,so the lowercase keys agents tend to emit (
weight,url,method) load too.Tests
New cases: array form, single-element array, lowercase keys, empty array (→
no calls), malformed/truncated array, and the file path. All existing streamtests stay green.
go test -race ./...,go vet, andgofmtall clean.Verified end-to-end against a local server — the previously-failing array
invocation now runs and reports per-status-code counts correctly.
🤖 Generated with Claude Code