Mailglass.Credo.NoRawSandboxOwnership (Mailglass v2.2.2)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Test code acquires and releases Ecto Sandbox pool ownership through Mailglass.TestSupport.SandboxOwnership, not through Ecto.Adapters.SQL.Sandbox directly.

Both confirmed HARNESS-01 leak sites (test/support/mailer_case.ex and test/mailglass/properties/webhook_idempotency_convergence_test.exs) shared one shape: acquire, then work that can raise, then register the release — with the release registered last, so a raise in the middle loses it entirely. SandboxOwnership.checkout!/1 makes that ordering structurally impossible to re-type by registering the release on the statement immediately following acquisition. A raw Sandbox.start_owner!/ Sandbox.mode/Sandbox.checkout call outside the sanctioned door can reintroduce the exact ordering bug this check exists to prevent.

Check-Specific Parameters

Use the following parameters to configure this check:

:allowed_modules

Modules explicitly allowed to call Ecto.Adapters.SQL.Sandbox's ownership functions directly.

This parameter defaults to [Mailglass.TestSupport.SandboxOwnership, Mailglass.TestSupport.SandboxOwnershipTest].

:included_path_prefixes

Only files in these path prefixes are linted.

This parameter defaults to ["test/"].

:forbidden_functions

Ecto.Adapters.SQL.Sandbox function names that are disallowed outside the door.

This parameter defaults to [:mode, :start_owner!, :stop_owner, :checkout, :checkin].

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.