CodeSampleX

Sample

mustermann 4.0.0: Expand Mustermann route patterns with additional query parameters by configuring additional_values :append or :ignore instead of relying on default :raise

Verified sample for gem mustermann 4.0.0: Expand Mustermann route patterns with additional query parameters by configuring additional_values :append or…

sha256:a52cc147c58747a0e7df759e9f657bf423a1c13618128814839ec773ff27ad99

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
Expand Mustermann route patterns with additional query parameters by configuring additional_values :append or :ignore instead of relying on default :raise
Packages
Symbols
  • Mustermann::Expander#additional_values
  • Mustermann::Expander#expand
  • Mustermann::Pattern#expand
  • Mustermann::Expander.new
  • Mustermann::ExpandError
Environment
ruby
Created
2026-08-16T15:55:42Z

Contract

  1. assert Mustermann::Expander.new without additional_values defaults additional_values to :raise and raises Mustermann::ExpandError on unexpected keys instead of appending query params
  2. assert Pattern#expand without behavior argument defaults to :raise when extra keys are provided
  3. assert Expander with additional_values: :append formats extra keys as query string parameters
  4. assert Pattern#expand with :append formats extra keys as query string parameters
  5. assert Expander with additional_values: :ignore omits extra keys from the expanded path without error
  6. assert Expander with :append or :ignore still raises Mustermann::ExpandError when required pattern captures are missing

Files

  • Gemfile
  • Gemfile.lock
  • NOTES.md
  • csx.json
  • lib/url_builder.rb
  • test/contract.rb

Download the source artifact (tar.gz)

Source

Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

gem "mustermann", "4.0.0"
gem "minitest", "5.27.0"
Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:
    mustermann (4.0.0)

PLATFORMS
  ruby
  x86_64-linux

DEPENDENCIES
  mustermann (= 4.0.0)

BUNDLED WITH
   2.6.9
NOTES.md
# Mustermann Expander Default Option Traps

## What search_known_solution answered
`search_known_solution` returned no pre-existing match for Mustermann expander options and default value behaviors. Existing known samples in the library address pattern compiler option flags (`sha256:7d4ccb66cb528b53fde3dfb425c69f45c9737788639d43fca70176e3fa449e5e`) and the `Pattern#hash` bitwise XOR fix (`sha256:f5ed8932d74e55651eebfba42ffbf53e5f87eb5c8edb2c4e96ef4d1c71159ab1`). This sample isolates the default expansion behavior of `Mustermann::Expander` and `Mustermann::Pattern#expand`.

## What a model would have written instead
A model or developer assumes that expanding a route pattern with extraneous key-value pairs (such as `tab: "profile"` or `sort: "desc"`) will automatically append those pairs as URI query parameters (`?tab=profile`) or silently ignore them, expecting `additional_values` to default to `:append` or `:ignore`.

## How the wrong version fails
Loudly raises `Mustermann::ExpandError: cannot expand with keys [...]` at expansion time whenever extra parameters are supplied without explicitly specifying `:append` or `:ignore`.
csx.json
{"case":{"believed":"Mustermann::Expander and Pattern#expand default to appending unexpected parameters as query strings when generating URLs from route patterns.","caseId":"case:sha256:552bd753e495e8e29503e9c9e325a2a61ca33f2e7dec54f24d758334b499b116","contract":["assert Mustermann::Expander.new without additional_values defaults additional_values to :raise and raises Mustermann::ExpandError on unexpected keys instead of appending query params","assert Pattern#expand without behavior argument defaults to :raise when extra keys are provided","assert Expander with additional_values: :append formats extra keys as query string parameters","assert Pattern#expand with :append formats extra keys as query string parameters","assert Expander with additional_values: :ignore omits extra keys from the expanded path without error","assert Expander with :append or :ignore still raises Mustermann::ExpandError when required pattern captures are missing"],"goal":"Expand Mustermann route patterns with additional query parameters by configuring additional_values :append or :ignore instead of relying on default :raise","kind":"HOW","packages":["pkg:gem/mustermann@4.0.0"],"schemaVersion":1,"symbols":["Mustermann::Expander#additional_values","Mustermann::Expander#expand","Mustermann::Pattern#expand","Mustermann::Expander.new","Mustermann::ExpandError"]},"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/mustermann@4.0.0"],"schemaVersion":1,"symbols":["Mustermann::Expander#additional_values","Mustermann::Expander#expand","Mustermann::Pattern#expand","Mustermann::Expander.new","Mustermann::ExpandError"],"verifierAdapter":"rubygems@1"}
lib/url_builder.rb
# frozen_string_literal: true

require "mustermann"
require "mustermann/expander"

module UrlBuilder
  class << self
    # Creates an expander with default options (demonstrating default additional_values: :raise)
    def default_expander(*patterns)
      Mustermann::Expander.new(*patterns)
    end

    # Creates an expander configured to append unexpected parameters as query strings
    def query_expander(*patterns)
      Mustermann::Expander.new(*patterns, additional_values: :append)
    end

    # Creates an expander configured to ignore unexpected parameters
    def strict_path_expander(*patterns)
      Mustermann::Expander.new(*patterns, additional_values: :ignore)
    end

    # Expand route using Pattern#expand directly
    def expand_pattern(pattern, behavior = nil, **params)
      p = pattern.is_a?(Mustermann::Pattern) ? pattern : Mustermann.new(pattern)
      if behavior
        p.expand(behavior, params)
      else
        p.expand(params)
      end
    end
  end
end
test/contract.rb
# frozen_string_literal: true

require "minitest/autorun"
require "mustermann"
require "mustermann/expander"
require_relative "../lib/url_builder"

class MustermannExpanderContractTest < Minitest::Test
  def test_default_additional_values_is_raise_and_fails_on_extra_keys
    # When initialized without explicit additional_values, the default is :raise
    expander = UrlBuilder.default_expander("/users/:id")
    assert_equal :raise, expander.additional_values

    # Naive assumption: expander will append ?tab=profile or ignore extra keys.
    # Reality: default :raise causes ExpandError when unknown keys are passed.
    error = assert_raises(Mustermann::ExpandError) do
      expander.expand(id: 42, tab: "profile")
    end
    assert_match(/cannot expand with keys \[:id, :tab\], possible expansions: \[:id\]/, error.message)

    # Valid expansion with exact keys succeeds under default :raise
    assert_equal "/users/42", expander.expand(id: 42)
  end

  def test_pattern_expand_without_behavior_defaults_to_raise
    # Calling Pattern#expand without behavior symbol defaults to :raise
    pattern = Mustermann.new("/articles/:slug")

    error = assert_raises(Mustermann::ExpandError) do
      UrlBuilder.expand_pattern(pattern, slug: "hello-world", draft: "true")
    end
    assert_match(/cannot expand with keys \[:draft, :slug\], possible expansions: \[:slug\]/, error.message)

    # Exact key match works
    assert_equal "/articles/hello-world", UrlBuilder.expand_pattern(pattern, slug: "hello-world")
  end

  def test_expander_with_append_formats_extra_keys_as_query_string
    # Configuring additional_values: :append serializes extra key-value pairs into query parameters
    expander = UrlBuilder.query_expander("/users/:id")
    assert_equal :append, expander.additional_values

    url = expander.expand(id: 42, tab: "profile", sort: "desc")
    assert_equal "/users/42?tab=profile&sort=desc", url
  end

  def test_pattern_expand_with_append_positional_argument
    # Passing :append as the first argument to Pattern#expand appends query parameters
    pattern = Mustermann.new("/products/:category/:id")
    url = UrlBuilder.expand_pattern(pattern, :append, category: "books", id: 99, currency: "USD")
    assert_equal "/products/books/99?currency=USD", url
  end

  def test_expander_with_ignore_omits_extra_keys
    # Configuring additional_values: :ignore silently discards extraneous parameters
    expander = UrlBuilder.strict_path_expander("/reports/:report_id")
    assert_equal :ignore, expander.additional_values

    url = expander.expand(report_id: 101, debug: "true", format: "json")
    assert_equal "/reports/101", url
  end

  def test_missing_required_captures_still_raise_under_append_or_ignore
    # Even when configured with :append or :ignore, missing required route parameters raises ExpandError
    appending_expander = UrlBuilder.query_expander("/orders/:order_id/items/:item_id")
    ignoring_expander = UrlBuilder.strict_path_expander("/orders/:order_id/items/:item_id")

    assert_raises(Mustermann::ExpandError) do
      appending_expander.expand(order_id: 5, status: "pending")
    end

    assert_raises(Mustermann::ExpandError) do
      ignoring_expander.expand(item_id: 12)
    end
  end
end

Origin Seeder

csx-seed