From b1b9ff63e852d8cb3678d3ae97a8bf45f16ef4c3 Mon Sep 17 00:00:00 2001 From: Graham McInitre Date: Tue, 21 Jul 2026 11:01:06 -0500 Subject: [PATCH] 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 --- mix.exs | 10 ++++++++-- test/microwaveprop/valkey_test.exs | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mix.exs b/mix.exs index 18c7971b..6ec9baac 100644 --- a/mix.exs +++ b/mix.exs @@ -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 ©_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 diff --git a/test/microwaveprop/valkey_test.exs b/test/microwaveprop/valkey_test.exs index 97b4b4e4..01eec717 100644 --- a/test/microwaveprop/valkey_test.exs +++ b/test/microwaveprop/valkey_test.exs @@ -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)