fix: isolate precommit steps with cmd, split test alias from DB setup

- Move ecto.create/ecto.migrate from test alias to test.setup
- Use cmd MIX_ENV=test in precommit to isolate each step in a fresh process
- Move Mox.defmock from test_helper.exs to valkey_test.exs
This commit is contained in:
Graham McInitre 2026-07-21 11:01:06 -05:00
parent 255c99cb36
commit b1b9ff63e8
2 changed files with 14 additions and 4 deletions

10
mix.exs
View file

@ -150,7 +150,8 @@ defmodule Microwaveprop.MixProject do
"deps.get": ["deps.get", &apply_dep_patches/1],
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
"test.setup": ["ecto.create --quiet", "ecto.migrate --quiet"],
test: ["test"],
"assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
"assets.build": [
"compile",
@ -164,7 +165,12 @@ defmodule Microwaveprop.MixProject do
&copy_leaflet_images/1,
"phx.digest"
],
precommit: ["compile", "deps.unlock --check-unused", "format", "credo --strict", "test"]
precommit: [
"format --check-formatted",
"cmd MIX_ENV=test mix test",
"deps.unlock --check-unused",
"cmd MIX_ENV=test mix credo --strict"
]
]
end

View file

@ -8,12 +8,16 @@ defmodule Microwaveprop.ValkeyTest do
import Mox
# Defined here (not in test_helper.exs) so test_helper can load even
# when the precommit chain has purged Mox from the code path.
alias Microwaveprop.Valkey
# Register Mox mock as the adapter and fake a Redix connection so
# configured?() returns true, letting command/pipeline run through the mock.
alias Microwaveprop.Valkey.Conn
alias Microwaveprop.Valkey.MockAdapter
Mox.defmock(MockAdapter, for: Microwaveprop.Valkey.Adapter)
# Register Mox mock as the adapter and fake a Redix connection so
# configured?() returns true, letting command/pipeline run through the mock.
setup do
prev_url = Application.get_env(:microwaveprop, :valkey_url)
prev_adapter = Application.get_env(:microwaveprop, :valkey_adapter)