Skip to content

fix(assert): Render header values readably; document multi-value - #101

Merged
korya merged 1 commit into
masterfrom
korya-fix-header-eq-rendering
Aug 11, 2026
Merged

fix(assert): Render header values readably; document multi-value#101
korya merged 1 commit into
masterfrom
korya-fix-header-eq-rendering

Conversation

@korya

@korya korya commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Problem

A failed header assertion printed Go's slice syntax at the user, and nothing anywhere said that a header can hold more than one value.

$ http-assert --assert-header-eq 'X-Custom: wrong' http://.../ok
- header[X-Custom]: expected "wrong", got ["abc123"]
                                          ^^^^^^^^^^ Go slice syntax, for a header with one value

That bracket was also the only place the tool admitted the model is a list. --assert-header and --assert-header-eq hold when any value matches, so this passes against a response that sets three cookies:

$ http-assert --assert-header-eq 'Set-Cookie: session=abc' https://example.com/login
[+] PASSED

The flag said "Assert header equals the provided value" and the README said "exact value". Both read as a claim about the only value, and neither --help nor the README mentioned multi-valued headers at all.

Solution

Render values the way a person writes them, and write the matching rule down in the three places a user would look.

Before / after, for the same two responses:

- header[X-Custom]: expected "wrong", got ["abc123"]          →  got "abc123"
- header[X-Dup]: expected "wrong", got ["first" "second"]     →  got "first", "second"

The semantics are unchanged — the ticket is right that any-value is the sensible default. What changes is that --help, the flag descriptions and the README now say so, deliberately placed next to the existing paragraph about repeating the flag, which is a different thing and was the only nearby text a reader could mistake for this one.

The reported flag was one of three

--assert-header and --assert-header-missing formatted the same []string the same way, so the bug had three manifestations, not one:

Assertion Before
--assert-header-eq expected "nope", got ["a=1" "b=2"]
--assert-header expected to match "^nope$", got ["a=1" "b=2"]
--assert-header-missing expected to be missing, got ["a=1" "b=2"]

Fixing only the reported one would have left two assertions rendering disagreements with it.

Verification

New e2e tests cover the any-value rule for both matching flags, the strictness of --assert-header-missing, both renderings, and a guard that no header failure contains got [ again. They were mutation-checked: with headerValues reverted to %q on the slice, five of the seven subtests fail.

Manually reproduced the ticket's exact commands against a server with X-Dup: first / X-Dup: second and three Set-Cookie headers, before and after.

Other Changes

  • No behaviour change. The only observable difference is the text of a failure message; exit codes, matching and everything else are untouched.
  • Eight unit expectations that pinned the bracketed form were updated, plus the --assert-header-missing regex that matched got \[.*\].
  • No visual change — CLI only.

Closes #97

🤖 Generated with Claude Code

A failed header assertion printed Go's slice syntax at the user: a header that
only ever carried one value came back as `got ["abc123"]`, which reads as
though something bracketed had happened to it. Values are now written the way a
person writes them -- `got "abc123"` for one, `got "first", "second"` for
several.

The bracket was the only place the tool admitted that a header is a list.
--assert-header and --assert-header-eq hold when ANY value matches, so
--assert-header-eq 'Set-Cookie: session=abc' passes against a response setting
three cookies. That is the right default and is not changing, but "equals" and
the README's "exact value" both read as a claim about the only value, and
nothing in --help or the README mentioned multiple values at all. Both now say
so, next to the paragraph about repeating the flag, which is a different thing
and was the only nearby text a reader could mistake for this one.

The rendering was wrong in three assertions rather than the one reported:
--assert-header and --assert-header-missing formatted the same []string the
same way. Fixing only the reported flag would have left two assertions
disagreeing with it.

Closes #97

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CrknafJSP5hF8u865cbnqX
@korya
korya marked this pull request as ready for review August 11, 2026 11:40
@korya
korya merged commit a1ec603 into master Aug 11, 2026
8 checks passed
@korya
korya deleted the korya-fix-header-eq-rendering branch August 11, 2026 11:40
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.

--assert-header-eq matches any value of a repeated header, and renders a Go slice on failure

1 participant