CodeSampleX

Exemplo

req 0.7.2: Measure overlapping consumption of one shared Agent-backed request body in Req 0.7.2

Amostra verificada para hex req 0.7.2: Measure overlapping consumption of one shared Agent-backed request body in Req 0.7.2. O contrato rodou em elixir 1 …

sha256:b4ec0f05188bf193c38ae8422c6670ea945c3bdf1cb278a15a324708be155cc6

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
2
Ambiente declarado elixir 1 linux x64 elixir 1 elixir mix

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
elixir 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-17
elixir 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-18

Caso

HOW
Objetivo
Measure overlapping consumption of one shared Agent-backed request body in Req 0.7.2
Pacotes
Símbolos
  • Req.new
  • Req.request!
  • Req.Response.new
Ambiente
elixir 1
Criado
2026-08-17T04:46:38Z

Contrato

  1. assert two overlapping Req.request! calls consume exactly four chunks in total from the shared Agent-backed stream
  2. assert at least one response body differs from the complete four-chunk sequence, proving the one-shot stream is shared rather than duplicated

Arquivos

  • NOTES.md
  • csx.json
  • mix.exs
  • mix.lock
  • test/contract.exs
  • test/contract_test.exs
  • test/test_helper.exs

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

NOTES.md
# Req 0.7.2 shared one-shot request body

The body stream pulls four values from one Agent. Two overlapping calls share
that same stream state: the response bodies contain four chunks in total, and
at least one response differs from the complete sequence. The adapter is an
in-process function, so the contract opens no socket and asserts no behavior
for another Req version.
csx.json
{"buildCommand":["mix","deps.compile","--no-deps-check"],"case":{"believed":"Two overlapping Req calls made from one request value each enumerate a shared one-shot body independently and both receive all four chunks.","caseId":"case:sha256:e13ef99f4726ffd0f7003afbd9bc317af71926f3009b882d78673ac7c5000429","contract":["assert two overlapping Req.request! calls consume exactly four chunks in total from the shared Agent-backed stream","assert at least one response body differs from the complete four-chunk sequence, proving the one-shot stream is shared rather than duplicated"],"goal":"Measure overlapping consumption of one shared Agent-backed request body in Req 0.7.2","kind":"HOW","packages":["pkg:hex/req@0.7.2"],"schemaVersion":1,"symbols":["Req.new","Req.request!","Req.Response.new"]},"contractCommand":["mix","test","--no-deps-check"],"environment":{"arch":"x64","ecosystem":"hex","executionContext":"elixir","language":"elixir","os":"linux","packageManager":"mix","runtime":"elixir","runtimeVersion":"1","schemaVersion":1},"license":"MIT-0","packages":["pkg:hex/req@0.7.2"],"schemaVersion":1,"symbols":["Req.new","Req.request!","Req.Response.new"],"verifierAdapter":"hex@1"}
mix.exs
defmodule CsxReqSharedBody.MixProject do
  use Mix.Project

  def project do
    [
      app: :csx_req_shared_body,
      version: "0.1.0",
      elixir: "~> 1.15",
      deps: [{:req, "0.7.2"}]
    ]
  end

  def application, do: [extra_applications: []]
end
mix.lock
%{
  "finch": {:hex, :finch, "0.23.0", "e3f9287ac25a8832f848b144c2b57346aac65b205e2e0629a52adfe6507fd837", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "80e58d3f936f57e3fdf404f83a3642897ae6d9fb642934e46da4d8fe761b99d5"},
  "hpax": {:hex, :hpax, "1.0.4", "777de5d433b0fbdc7c418159c8055910faa8047ffdb3d6b31098d2a46cd7685c", [:mix], [], "hexpm", "afc7cb142ebcc2d01ce7816190b98ce5dd49e799111b24249f3443d730f377ca"},
  "jason": {:hex, :jason, "1.4.5", "2e3a008590b0b8d7388c20293e9dcc9cf3e5d642fd2a114e4cbbb52e595d940a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b0c823996102bcd0239b3c2444eb00409b72f6a140c1950bc8b457d836b30684"},
  "mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"},
  "mint": {:hex, :mint, "1.9.3", "3337184d69179695c7a9f1714d92c11e629d36c8c037a21cf490131d3d150554", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "5f7c9342480c069dbbc4eeac3490303c9e01870ff01a7f1d29b6107054fc1e74"},
  "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
  "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},
  "req": {:hex, :req, "0.7.2", "364eae2e5f5c984f2dac6d71c07f8c8c89ce0bc49c4d746dacb7a306823020de", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:finch, "~> 0.21", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "c9cdfa276b05d8db2a27fda5d233e6858b764d47189d76cbb186e130a871ae0b"},
  "telemetry": {:hex, :telemetry, "1.4.2", "a0cb522801dffb1c49fe6e30561badffc7b6d0e180db1300df759faa22062855", [:rebar3], [], "hexpm", "928f6495066506077862c0d1646609eed891a4326bee3126ba54b60af61febb1"},
}
test/contract.exs
import ExUnit.Assertions

unless Code.ensure_loaded?(Req) do
  Path.wildcard("_build/dev/lib/*/ebin")
  |> Enum.each(&Code.append_path/1)

  unless Code.ensure_loaded?(Req) do
    raise "Req is not preloaded and could not be found in _build/dev/lib."
  end
end

defmodule TrapCaptureAdapter do
  def run(request) do
    {request, Req.Response.new(status: 200, body: Enum.to_list(request.body))}
  end
end

{:ok, token_agent} = Agent.start_link(fn -> ["a", "b", "c", "d"] end)

body_stream =
  Stream.unfold(token_agent, fn pid ->
    case Agent.get_and_update(pid, fn
           [] -> {nil, []}
           [head | tail] -> {head, tail}
         end) do
      nil -> nil
      value -> {value, pid}
    end
  end)

request = Req.new(
  url: "http://example.com/",
  method: :post,
  adapter: TrapCaptureAdapter,
  body: body_stream
)

results =
  1..2
  |> Enum.map(fn _ ->
    Task.async(fn -> Req.request!(request).body end)
  end)
  |> Enum.map(&Task.await(&1, 5_000))

assert Enum.any?(results, &(&1 != ["a", "b", "c", "d"]))
assert Enum.sum(Enum.map(results, &length(&1))) == 4
test/contract_test.exs
Code.require_file("contract.exs", __DIR__)
test/test_helper.exs
ExUnit.start()

Seeder de origem

csx-seed