Sample
sinatra 4.2.1: Handle Sinatra halt response tuple argument parsing where two arguments treat a headers hash as the response body rather than response headers
Verified sample for gem sinatra 4.2.1: Handle Sinatra halt response tuple argument parsing where two arguments treat a headers hash as the response body…
sha256:e49ccc79a51fa124beeb5256802042512379cdffd9e50c5c2a25720e40eaac5e
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 1
Declared environment
ruby linux x64 ruby ruby rubygems
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| ruby 3 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-16 |
| ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | SKIPPED | compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL CONTAINER_RUN · rubygems@1 |
2026-08-18 |
Case
HOW- Goal
- Handle Sinatra halt response tuple argument parsing where two arguments treat a headers hash as the response body rather than response headers
- Packages
- Symbols
-
- Sinatra::Base#halt
- Sinatra::Base#headers
- Environment
- ruby
- Created
- 2026-08-16T16:58:46Z
Contract
- assert halt with status code and hash assigns the hash to the response body and leaves headers unset
- assert halt with three arguments status, headers hash, and body string correctly sets both headers and body
- assert calling headers before halt status sets response headers with an empty body
- assert halt with single integer sets status with empty body
- assert halt with single string sets default status 200 and body
- assert halt with integer and string sets status and body
Files
- Gemfile
- NOTES.md
- csx.json
- test/contract.rb
Source
source "https://rubygems.org"
gem "sinatra", "4.2.1"
gem "minitest", "5.27.0"
# Notes
### What `search_known_solution` answered
`search_known_solution` returned no match for Sinatra response halting or header tuple evaluation (returning reference samples for unrelated libraries such as `sha256:8b87dbe3a6d2ab33ba4b807d61e35686efe22f1481d942766d8e1190783f14fe` covering shelf URL parsing). The only previously covered area was testing an in-process rack app with parameters.
### What a model would have written instead
A model assumes `halt 401, {'WWW-Authenticate' => 'Bearer ...'}` operates like standard HTTP tuple helper signatures, setting the HTTP status code and response headers with an empty body.
### How the wrong version fails
Silently omits the headers from the response and assigns the Hash object directly to the response body; downstream servers or Rack linters fail when iterating the body or when looking for expected HTTP header fields.
{"case":{"believed":"Calling halt with a status integer and headers hash sets the HTTP response status code and headers with an empty body.","caseId":"case:sha256:26c49c85301fc3cee9804ac718541f60ea8a08181d293b2c6e2053a249df9b4b","contract":["assert halt with status code and hash assigns the hash to the response body and leaves headers unset","assert halt with three arguments status, headers hash, and body string correctly sets both headers and body","assert calling headers before halt status sets response headers with an empty body","assert halt with single integer sets status with empty body","assert halt with single string sets default status 200 and body","assert halt with integer and string sets status and body"],"goal":"Handle Sinatra halt response tuple argument parsing where two arguments treat a headers hash as the response body rather than response headers","kind":"HOW","packages":["pkg:gem/sinatra@4.2.1"],"schemaVersion":1,"symbols":["Sinatra::Base#halt","Sinatra::Base#headers"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"rubygems","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/sinatra@4.2.1"],"schemaVersion":1,"symbols":["Sinatra::Base#halt","Sinatra::Base#headers"],"verifierAdapter":"rubygems@1"}
require "minitest/autorun"
require "sinatra/base"
require "rack/mock_request"
class SinatraHaltContractTest < Minitest::Test
class HaltApp < Sinatra::Base
set :environment, :test
set :raise_errors, true
set :show_exceptions, false
# Trap: two arguments (status, hash)
get "/two_arg_hash" do
halt 401, { "WWW-Authenticate" => "Bearer token" }
end
# Fix 1: three arguments (status, hash, body)
get "/three_arg" do
halt 401, { "WWW-Authenticate" => "Bearer token" }, ""
end
# Fix 2: explicit headers helper before halt status
get "/explicit_headers" do
headers "WWW-Authenticate" => "Bearer token"
halt 401
end
# Single integer
get "/single_int" do
halt 403
end
# Single string
get "/single_str" do
halt "direct body"
end
# Two args: status and string body
get "/status_and_body_str" do
halt 422, "unprocessable entity"
end
end
def test_two_arg_halt_treats_hash_as_body_instead_of_headers
status, headers, body = HaltApp.call(Rack::MockRequest.env_for("/two_arg_hash"))
# Status code is set to 401
assert_equal 401, status
# The hash was NOT applied to response headers
assert_nil headers["www-authenticate"]
assert_nil headers["WWW-Authenticate"]
# The hash was assigned directly to response body because Sinatra invoke pops the last element as body
assert_equal({ "WWW-Authenticate" => "Bearer token" }, body)
end
def test_three_arg_halt_correctly_sets_headers_and_body
status, headers, body = HaltApp.call(Rack::MockRequest.env_for("/three_arg"))
assert_equal 401, status
assert_equal "Bearer token", (headers["www-authenticate"] || headers["WWW-Authenticate"])
assert_equal [""], body
end
def test_explicit_headers_helper_persists_before_halt
status, headers, body = HaltApp.call(Rack::MockRequest.env_for("/explicit_headers"))
assert_equal 401, status
assert_equal "Bearer token", (headers["www-authenticate"] || headers["WWW-Authenticate"])
assert_equal [], body
end
def test_single_integer_sets_status_with_empty_body
status, _, body = HaltApp.call(Rack::MockRequest.env_for("/single_int"))
assert_equal 403, status
assert_equal [], body
end
def test_single_string_sets_default_status_and_body
status, _, body = HaltApp.call(Rack::MockRequest.env_for("/single_str"))
assert_equal 200, status
assert_equal ["direct body"], body
end
def test_two_arg_status_and_string_sets_status_and_body
status, _, body = HaltApp.call(Rack::MockRequest.env_for("/status_and_body_str"))
assert_equal 422, status
assert_equal ["unprocessable entity"], body
end
end