Extract reusable HTTP assertion library - #105
Merged
Merged
Conversation
Previously, every exported assertion and HTTP client lived in package main, so Go programs could not reuse them. Move the CLI to cmd/http-assert and make the root module an importable package with structured failures, evaluation errors, and ordered assertion outcomes. Keep retries, logging, exit codes, and human-readable formatting in the CLI. Preserve its behavior with the relocated subprocess suite while adding focused coverage for the public API and its error paths. Co-Authored-By: OpenAI Codex (GPT-5) <noreply@openai.com>
The zero-value library client previously inherited net/http's unbounded total request timeout, so a stalled endpoint could prevent a health check from returning. Use a shared client with a 20-second whole-request limit while preserving custom clients and shorter request-context deadlines. Co-Authored-By: OpenAI Codex (GPT-5) <noreply@openai.com>
Parsed assertion constructors correctly return errors, but static expressions become noisy when used inline. Add Must to preserve the constructor contract while giving programmer-owned status, regular-expression, and jq assertions the conventional one-line panic form. Co-Authored-By: OpenAI Codex (GPT-5) <noreply@openai.com>
korya
marked this pull request as ready for review
August 30, 2026 23:01
This was referenced Aug 31, 2026
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.
Problem
Go programs cannot reuse http-assert's client or assertions because every exported type currently lives inside the CLI package.
The command already has a composable assertion model, response decoding, and an HTTP client, but
package mainmakes that functionality unimportable. Keeping retry orchestration and formatted error strings in the same layer would also freeze CLI policy into any public API. Using Go's default HTTP client would additionally leave library calls without a total request deadline.Solution
Make the root module an importable assertion library and move the command, retries, and presentation into
cmd/http-assert.flowchart LR Consumer["Go package"] --> Library["github.com/korya/http-assert"] CLI["cmd/http-assert"] --> Library Library --> HTTP["net/http"] CLI --> Policy["retries, logs, formatting, exit codes"]The library invokes its configured
http.Clientonce and returns ordered, structured outcomes that distinguish assertion failures from evaluation errors. It validates requests and assertions before transport, retains decoded response bytes for consumers, and exposes all existing assertion constructors without adding retry or formatting helpers to the initial API.The zero-value client uses a shared 20-second whole-request timeout instead of the unbounded
http.DefaultClient; callers can still inject another client or apply a shorter context deadline. Constructors that parse status expressions, regular expressions, or jq queries retain explicit error returns, whileha.Must(...)provides the conventional one-line panic form for static, programmer-controlled expressions.The CLI imports the library as
ha, preserves its existing human-readable output and exit behavior, and remains the sole owner of retries. Source installs now usegithub.com/korya/http-assert/cmd/http-assert; published binary names and archives remain unchanged.No visual change: this refactors a Go API and CLI boundary while intentionally preserving terminal output.
Other Changes
ha.Mustpaths. Merged E2E coverage reaches 100% of CLI statements; library coverage reaches 99.6%, with only the defensive zstd constructor-error branch not inducible through its fixed valid options.🤖 Generated with Claude Code