Skip to content

Make both boolean assertions negate the same way - #80

Merged
korya merged 1 commit into
masterfrom
korya-fix-bool-assertion-negation
Aug 8, 2026
Merged

Make both boolean assertions negate the same way#80
korya merged 1 commit into
masterfrom
korya-fix-bool-assertion-negation

Conversation

@korya

@korya korya commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Problem

Two boolean assertions of the same shape did two different things with =false, and one of them told the user they had made no assertion.

$ http-assert --assert-ok=false http://…/500
[+] PASSED                                       ← asserted the status IS an error

$ http-assert --assert-body-empty=false http://…/ok
Error: Cannot perform request: no assertions defined

The second is the one that matters. The user named an assertion and was told there were none — the run cannot even be said to have failed, it never started. Nothing in the README, --help or the package comment described either behaviour, so neither was discoverable except by trying it.

Solution

=false now selects the opposite assertion on both flags.

$ http-assert --assert-body-empty=false http://…/ok
[+] PASSED                                       ← asserted the body is not empty

That reading is the one --assert-ok already had; it is the only one under which naming a flag can never yield nothing; and it adds a genuinely useful assertion by the shortest available route.

Invocation Before After
--assert-ok=false asserts status IS an error unchanged
--assert-body-empty=false registers nothing asserts the body is not empty

The pairing lives in one place now

The two flags drifted apart because nothing connected them — one was written with Changed(), the other with the value, and no rule said they were the same kind of thing. That is the same root cause as #35, where the fix was likewise to derive the rule rather than repeat it per flag: rejectRepeats reads the flag's type instead of consulting a list.

boolAssertion(cmd, name, whenTrue, whenFalse) is the equivalent here. A boolean assertion added later gets the behaviour on the day it is added, rather than whenever someone notices.

Deliberately not done

The issue floats promoting this to first-class --assert-not-ok and --assert-body-not-empty flags. That is a feature, not the fix — =false already works, is now consistent, and is now documented. Adding two flags for a spelling that exists would need its own argument about which is canonical, and it does not have to be made to close this.

Other Changes

Negation is documented in three places that previously described neither behaviour: the README's assertion section (with both flags shown doing something a reader would actually want), the --help prose, the two flag descriptions, and the package comment.

TestKnownIssue32NegatedBooleanFlagsDiffer is deleted, replaced by TestE2EAssertBooleanNegation — both flags, both directions, both outcomes, eight cases. Plus a guard that no negated flag is ever treated as no assertion at all, which is the specific failure this closes, and a check that repeating a negated flag is still refused, since naming it twice is still naming it twice.

Test_AssertBodyNotEmpty covers the new constructor including a nil body (what a 204 produces) and whitespace, which counts as content. It also asserts the pair are exact inverses across five bodies — without that, =false could quietly mean something subtly other than "not that".

There are no screenshots because there is no rendered UI; this tool's user-visible surface is terminal output, shown inline above.

Closes #32

Related:

🤖 Generated with Claude Code

https://claude.ai/code/session_019EMMhgmTkbzAsmeNy97PrP

Base automatically changed from korya-fix-empty-body-assertions to master August 8, 2026 13:11
--assert-ok=false asserted the status IS an error. --assert-body-empty=false
asserted nothing at all, and the run died reporting that no assertion had
been made:

    $ http-assert --assert-body-empty=false http://…/ok
    Error: Cannot perform request: no assertions defined

Two flags of the same shape, one of them telling a user who had just
named an assertion that there were none. Neither behaviour was written
down anywhere.

=false now selects the opposite assertion on both, so
--assert-body-empty=false asserts the body is not empty. That is the
reading --assert-ok already had, it is the only one under which naming a
flag cannot yield nothing, and it adds the assertion by the shortest
route rather than by a new flag.

The pairing lives in one helper rather than being written out per flag.
The two drifted apart because nothing connected them -- the same root as
#35, where the fix was likewise to derive the rule instead of repeating
it. A boolean assertion added later gets the behaviour on the day it is
added.

Negation is now documented in the README, --help and the package comment.
Repeating a negated flag is still refused, since naming it twice is still
naming it twice.

Closes #32

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019EMMhgmTkbzAsmeNy97PrP
@korya
korya force-pushed the korya-fix-bool-assertion-negation branch from df3d77c to aacdc72 Compare August 8, 2026 13:15
@korya
korya marked this pull request as ready for review August 8, 2026 13:17
@korya
korya merged commit 2ff7841 into master Aug 8, 2026
7 checks passed
@korya
korya deleted the korya-fix-bool-assertion-negation branch August 8, 2026 13: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.

--assert-body-empty=false and --assert-ok=false behave inconsistently

1 participant