Skip to content

Idea: cap a response body at the first N lines in a verified .responses file #54

Open

Description

@Mpdreamz

The idea. Let a .http snapshot keep only the first N lines of a response body, so a large API response does not fill a verified file or make it churn.

Why. elastic/docs-builder#4791 needed this and wrote its own scrubber, BodyScrubbers.FirstQuotedLine, which keeps the first line of each quoted text body and replaces the rest with > …, so a page snapshot shows its title and not its content. A built-in option would replace that helper and work for every consumer.

Sketch (not decided, not scheduled):

  • A per-request directive in the .http file, # @snapshot-lines 20, so the cap travels with the file and a test and snap http run (which share one .verified.responses) cannot disagree. Other .http tools treat it as a comment. Plus a MaxBodyLines option as the default for every response and for single-response MatchHttpSnapshot.
  • Applied where the body is written, HttpResponseText.AppendBody, so both entry points get it. Text bodies are already quoted with > ; the cut ends in a constant > … line. A constant marker, not "… 412 more lines": a count would change with every content edit and defeat the point.
  • The received file is cut the same way, so a failing run cannot show what is past the cap. That pairs with the @expect checks from .http files: @expect checks on a response, @readonly, and a read-only run #49, which assert on the whole response while the snapshot keeps only the head.

Open: JSON. A JSON body is written as raw pretty-printed lines and parsed back as a tree, so cutting it at N lines leaves invalid JSON. Quoting it as text past the cap works but changes that section's shape when the cap is crossed. What is wanted instead is a JSONPath-style truncate syntax, such as keeping the first N items of $.items[*], so the body stays valid JSON and keeps tree diffs. That needs its own design.

Also open: a single very long line (minified HTML or JSON) defeats a line cap, so a character cap may be needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions