CodeSampleX

Ejemplo

nimble_pool 1.1.0: Verify that start_link eagerly checks worker module existence and validates pool_size type

Muestra verificada para hex nimble_pool 1.1.0: Verify that start_link eagerly checks worker module existence and validates pool_size type. El contrato se…

sha256:f3bdf79601e6d0cb079ae5187e83d3ea06e4b2ed2c35f223db15ccb9dd6be4d8

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
2
Claves de firma que lo compilaron
2
Entorno declarado elixir linux x64 elixir elixir mix

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
elixir 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-16
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
Verify that start_link eagerly checks worker module existence and validates pool_size type
Paquetes
Símbolos
  • NimblePool.start_link
Entorno
elixir
Creado
2026-08-16T15:08:03Z

Contrato

  1. NimblePool.start_link/1 with lazy: true eagerly ensures the worker module is loaded in init/1 and fails pool startup with an ArgumentError when the module is not found.
  2. NimblePool.start_link/1 strictly validates that :pool_size is a positive integer, raising an ArgumentError when passed atom options like :infinity that passed comparison in earlier versions.
  3. NimblePool.start_link/1 raises an ArgumentError when the required :worker option is omitted.

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

NOTES.md
# NimblePool Worker and Option Validation

## What search_known_solution answered
`search_known_solution` returned existing sample `sha256:5dad1cd6420c0a31a656d4e6fa5d703e0a95522ccd354cd1b912b127624eaab9` (which demonstrates the `terminate_pool/2` GenServer state map structure on `v1.1.0`) and sample `sha256:604e80e0559a8cef2559c7cc549e4743383c6e7bd9a35924598667d1152f2ad7` (which proves idle worker ping throttling); this sample investigates startup option and worker module load validation changes introduced in `v1.1.0`.

## How the wrong version fails
On `v1.0.0`, starting a lazy pool (`lazy: true`) with an unresolvable worker module or an atom like `pool_size: :infinity` silently succeeds with a green build, returning `{:ok, pid}` instead of failing pool startup with an `ArgumentError`.
csx.json
{"buildCommand":["mix","deps.compile","--no-deps-check"],"case":{"believed":"A model expects that starting a lazy pool with lazy: true defers worker module validation until checkout, allowing start_link to return {:ok, pid} even when given an unresolvable worker module or an atom :infinity for pool_size.","caseId":"case:sha256:5343fe19c31eb054d01a5fce6de44c20f27beadbabe563192c3471728f6effda","contract":["NimblePool.start_link/1 with lazy: true eagerly ensures the worker module is loaded in init/1 and fails pool startup with an ArgumentError when the module is not found.","NimblePool.start_link/1 strictly validates that :pool_size is a positive integer, raising an ArgumentError when passed atom options like :infinity that passed comparison in earlier versions.","NimblePool.start_link/1 raises an ArgumentError when the required :worker option is omitted."],"goal":"Verify that start_link eagerly checks worker module existence and validates pool_size type","kind":"HOW","packages":["pkg:hex/nimble_pool@1.1.0"],"schemaVersion":1,"symbols":["NimblePool.start_link"]},"contractCommand":["mix","test","--no-deps-check"],"environment":{"arch":"x64","ecosystem":"hex","executionContext":"elixir","language":"elixir","os":"linux","packageManager":"mix","runtime":"elixir","schemaVersion":1},"license":"MIT-0","packages":["pkg:hex/nimble_pool@1.1.0"],"schemaVersion":1,"symbols":["NimblePool.start_link"],"verifierAdapter":"hex@1"}
mix.exs
defmodule NimblePoolOptionValidation.MixProject do
  use Mix.Project

  def project do
    [
      app: :nimble_pool_option_validation,
      version: "0.1.0",
      elixir: "~> 1.14 or ~> 1.15 or ~> 1.16 or ~> 1.17 or ~> 1.18",
      deps: deps()
    ]
  end

  def application do
    [extra_applications: []]
  end

  defp deps do
    [{:nimble_pool, "1.1.0"}]
  end
end
mix.lock
%{
  "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},
}
test/contract_test.exs
defmodule WorkerValidationContractTest do
  use ExUnit.Case, async: false

  defmodule ValidWorker do
    @behaviour NimblePool

    @impl true
    def init_pool(arg), do: {:ok, arg}

    @impl true
    def init_worker(pool_state), do: {:ok, :worker_state, pool_state}

    @impl true
    def handle_checkout(_command, _from, worker_state, pool_state) do
      {:ok, :client_state, worker_state, pool_state}
    end

    @impl true
    def handle_checkin(_client_state, _from, worker_state, pool_state) do
      {:ok, worker_state, pool_state}
    end

    @impl true
    def terminate_worker(_reason, _worker_state, pool_state) do
      {:ok, pool_state}
    end
  end

  test "lazy: true pool eagerly validates worker module existence during start_link" do
    Process.flag(:trap_exit, true)
    unloaded_module = :NonExistentWorkerModule

    result = NimblePool.start_link(worker: {unloaded_module, :arg}, lazy: true)

    assert match?({:error, {%ArgumentError{message: "failed to load worker module " <> _}, _}}, result)
  end

  test "pool_size must be a positive integer, rejecting atoms like :infinity" do
    assert_raise ArgumentError, ~r/pool_size must be a positive integer/, fn ->
      NimblePool.start_link(worker: {ValidWorker, []}, pool_size: :infinity, lazy: true)
    end
  end

  test "omitting the required :worker option raises ArgumentError" do
    assert_raise ArgumentError, ~r/missing required :worker option/, fn ->
      NimblePool.start_link([])
    end
  end
end
test/test_helper.exs
ExUnit.start()

Seeder de origen

csx-seed